You are on page 1of 2

PROGRAM

import java.io.*;
class sentence
{
char ch,ch1;
String s,ns,nsr,wdr,ew="";
int l,i,ctr=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
void show()throws IOException
{
System.out.println("Enter a sentence:");
s=br.readLine();
s=s.trim();
l=s.length();
x:
for(i=0;i<l;i++)
{
ch=s.charAt(i);
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'||ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')
{ ch1=s.charAt(i+1);
if(ch1=='a'||ch1=='e'||ch1=='i'||ch1=='o'||ch1=='u'||ch1=='A'||ch1=='E'||ch1=='I'||ch1=='U')
{ns=ns+ch;
continue x;
}
if(Character.isLowerCase(ch1))
{ns=ns+ch+Character.toUpperCase(ch1);
ctr++;
}
if(Character.isUpperCase(ch1))
ctr++;
if(ch1==' ')
{ns=ns+ch+" ";
ctr++;
}
if(ch1==' ')
{ns=ns+ch+" ";ctr++;
}
else
{
if(ctr==0)
ns=ns+ch;
if(ctr>0)
{ctr=0;
continue x;
}
}

System.out.println();
System.out.println(enter the word to be replaced");
wdr=br.readLine();
System.out.println("enter the replacing word");
ew=br.readLine();
for(int i=0;i<l;i++)
{ch=s.charAt(i);
if(ch!=' ')
wdr=wdr+ch;
else
{
if(wdr.equalsIgnoreCase(ew))
nsr=nsr+wdr+" ";
else
nsr=nsr+wdr+" ";
wdr="";
}
}
System.out.println("The string after replacing word : "+nsr);
}
}
}
}

You might also like