In this program, user will enter any sentence and all vowels will be placed at the beginning and then the other characters.
import java.io.*;
public class StringMan
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int i,len;
String str,sVowel,sOther;
void accept() throws Exception
{
sVowel="";
sOther="";
System.out.print("Enter Any Sentence: ");
str=br.readLine();
len=str.length();
for(i=0;i<len;i++)
{
if(isVowel(str.charAt(i)))
sVowel=sVowel+str.charAt(i);
else
sOther=sOther+str.charAt(i);
}
sVowel=sVowel+sOther;
System.out.print("\nOriginal Sentence: "+str);
System.out.print("\nModified Sentence: "+sVowel);
}
private boolean isVowel(char ch)
{
boolean bool=false;
ch=Character.toUpperCase(ch);
switch(ch)
{
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
bool=true;
}
return bool;
}
public static void main(String args[])throws Exception
{
StringMan ob=newStringMan();
ob.accept();
}
}
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int i,len;
String str,sVowel,sOther;
void accept() throws Exception
{
sVowel="";
sOther="";
System.out.print("Enter Any Sentence: ");
str=br.readLine();
len=str.length();
for(i=0;i<len;i++)
{
if(isVowel(str.charAt(i)))
sVowel=sVowel+str.charAt(i);
else
sOther=sOther+str.charAt(i);
}
sVowel=sVowel+sOther;
System.out.print("\nOriginal Sentence: "+str);
System.out.print("\nModified Sentence: "+sVowel);
}
private boolean isVowel(char ch)
{
boolean bool=false;
ch=Character.toUpperCase(ch);
switch(ch)
{
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
bool=true;
}
return bool;
}
public static void main(String args[])throws Exception
{
StringMan ob=newStringMan();
ob.accept();
}
}
No comments:
Post a Comment