Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mingbackmountain/2bb958d14ab19fef06034cd56a1feb21 to your computer and use it in GitHub Desktop.
Save mingbackmountain/2bb958d14ab19fef06034cd56a1feb21 to your computer and use it in GitHub Desktop.
import java.util.Scanner;
public class Check {
public static int countVowel(String x) {
int countvowel = 0;
x.toLowerCase();
for(int i =0;i<x.length();i++) {
if(x.charAt(i) == 'a'||x.charAt(i)=='e'||x.charAt(i)=='i'||x.charAt(i)=='o'||x.charAt(i)=='u') {
countvowel++;
}
}
return countvowel;
}
public static int countAlphabet(String x) {
int countalpha = 0;
x.toLowerCase();
for(int i =0;i<x.length();i++) {
if(x.charAt(i)!='a'&&x.charAt(i)!='e'&&x.charAt(i)!='i'&&x.charAt(i)!='o'&&x.charAt(i)!='u') {
countalpha++;
}
}
return countalpha;
}
public static int countDigit(String x) {
int count = 0;
if(Character.isDigit(x.charAt(0))) {
int number = Integer.parseInt(x);
if(number<0) {
number = number*-1;
}else if(number == 0) {
number = 1;
}
while(number>0) {
number = number/10;
count++;
}
}else {
return 0;
}
return count;
}
public static int countLowerCase(String x) {
int lower = 0;
for(int i =0;i<x.length();i++) {
if(Character.isLowerCase(x.charAt(i))) {
lower++;
}
}
return lower;
}
public static int countUpperCase(String x) {
int upper = 0;
for(int i =0;i<x.length();i++) {
if(Character.isUpperCase(x.charAt(i))) {
upper++;
}
}
return upper;
}
public static int ProgramCheck(String x,String y) {
if(x.equalsIgnoreCase("vowel")) {
return countVowel(y);
}else if(x.equalsIgnoreCase("alphabet")){
return countAlphabet(y);
}else if(x.equalsIgnoreCase("digit")) {
return countDigit(y);
}else if(x.equalsIgnoreCase("lowercase")) {
return countLowerCase(y);
}else if(x.equalsIgnoreCase("uppercase")) {
return countUpperCase(y);
}else {
return 1;
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String type;
String input;
System.out.println("count");
type = sc.nextLine();
input = sc.nextLine();
System.out.println(ProgramCheck(type, input));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment