Question
Replace vowels with stars in a 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:Q**ck Br*wn F*x j*mp*d *v*r th* l*zy d*g.
Share code with your friends
Share on whatsapp
Share on facebook
Share on twitter
Share on telegram
Code
import java.util.Scanner;
public class vowelToStar
{
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;
}
for(i=0;i< len;i++)
{
ch=sen.charAt(i);
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'||ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')
{
newSen=newSen+"*";
}
else
{
newSen=newSen+ch;
}
}
System.out.println("Original Sentence:"+sen);
System.out.println("new Sentence:"+newSen);
}
}