Write a java program to change all vowels in Capital and other in small :
import java.util.Scanner;public class VowelsIntoCap {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter Sentence ");
String str = sc.nextLine();
str = vowelsCap(str);
System.out.println("After changing vowels in capital \n" + str);
}
private static String vowelsCap(String str) {
char[] ch = str.toCharArray();
for (int i = 0; i < ch.length; i++) {
if (ch[i] == 'a' || ch[i] == 'e' || ch[i] == 'i' || ch[i] == 'o' || ch[i] == 'u') {
ch[i] = (char) (ch[i] - 32);
} else if (ch[i] >= 'A' && ch[i] <= 'Z') {
if ((ch[i] == 'A' || ch[i] == 'E' || ch[i] == 'I' || ch[i] == 'O' || ch[i] == 'U'))
ch[i] = (char) (ch[i]);
else {
ch[i] = (char) (ch[i] + 32);
}
} else {
ch[i] = (char) (ch[i]);
}
}
return new String(ch);
}
}
Comments
Post a Comment