To find out which vowel is repeated most in a given string

Chikul
Posted by Chikul under Others category on | Views : 6016
'Input : Enter String
public class vowelMax {

public static void main(String args[]) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a String : ");
String srcstr = br.readLine().toString();
int[] count = new int[5];
int maxchar = 0;

for(int i = 0; i < srcstr.length(); i++) {
switch(srcstr.charAt(i)) {
case 'a':
++count[0];
break;
case 'e':
++count[1];
break;
case 'i':
++count[2];
break;
case 'o':
++count[3];
break;
case 'u':
++count[4];
break;
default:
continue;
}
}
int temp;
int max = count[0];

for(int i = 1; i < 4; i++) {
if(count[i] > max) {
max = count[i];
maxchar = i;
}
}
switch(maxchar) {
case 0:
System.out.println("a is max");
break;
case 1:
System.out.println("e is max");
break;
case 2:
System.out.println("i is max");
break;
case 3:
System.out.println("o is max");
break;
case 4:
System.out.println("u is max");
default:
System.out.println("Vowels not available");
}
}
}

Comments or Responses

Login to post response