Question
Replace Vowels with next vowel(A with E,E with I,…U with A) in given sentence
Enter the Sentence:
quick brown fox jumped over the lazy dog.
Original Sentence:QUICK BROWN FOX JUMPED OVER THE LAZY DOG.
New Sentence:QAOCK BRUWN FUX JAMPID UVIR THI LEZY DUG.
Share code with your friends
Share on whatsapp
Share on facebook
Share on twitter
Share on telegram
Code
import java.util.Scanner;
public class replaceVowelsWithAdjacentVowels
{
public static void main()
{
int i,len=0;
String sen="",newSen="";
char ch= ' ';
Scanner sc=new Scanner(System.in);
System.out.println("Enter the Sentence:");
sen=sc.nextLine();
len=sen.length();
if(sen.charAt(len-1)!='.')
{
sen=sen+".";
len=len+1;
}
len=sen.length();
sen=sen.toUpperCase();
for(i=0;i< len;i++)
{
ch=sen.charAt(i);
if(ch=='A')
{
newSen=newSen+'E';
}
else if(ch=='E')
{
newSen=newSen+'I';
}
else if(ch=='I')
{
newSen=newSen+'O';
}
else if(ch=='O')
{
newSen=newSen+'U';
}
else if(ch=='U')
{
newSen=newSen+'A';
}
else
{
newSen=newSen+ch;
}
}
System.out.println("Original Sentence:"+sen);
System.out.println("New Sentence:"+newSen);
}
}