Computer Science, asked by youdhi, 5 months ago

Wap to accept a word and convert it into the lower case, If it is in the upper case. display the new word by replacing only the vowels with the next letter​

Answers

Answered by Anonymous
7

QUESTION:

Wap to accept a word and convert it into the lower case, If it is in the upper case. display the new word by replacing only the vowels with the next letter

ANSWER:

import java.util.Scanner; public class StringOp

public static void main(String[] args) { {

Scanner sc = new Scanner(System.in);

System.out.print("Enter the word: "); String str = sc.next(); //str stores original input

str = str.toLowerCase(); //str is now converted to Lower Case

/* ASCII CODES LIST:

* a - 97

* - 101

* i - 105

o - 111

* u - 117

*/

String newstr = ""; //newstr is the New String. It will store the modified word

for(int i=0;i<str.length();i++)

{

int ch = (int)str.charAt(i); //ch is the ASCII value of each character of str if((ch==97)||(ch==101)||(ch==105)|| (ch==111)||(ch==117)) //Condition for

checking if ch corresponds to a vowel {

ch++;

newstr += (char)ch;

}

else

{

}

newstr += (char)ch;

}

System.out.println("New String: }

"+newstr);

}

Similar questions