Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners ROTATE THE VOWELS IN A STRING!!!

Have Programming Question? Ask it here!
 
 
 


jas
ROTATE THE VOWELS IN A STRING!!!
1 Answer(s)      5 years and 11 months ago
Posted in : Java Beginners



Advertisement
View Answers

October 25, 2008 at 12:19 PM


Hi friend,


Code to help in replace character :


import jpb.*;

public class Replace{
public static void main(String s[]){
SimpleIO.prompt("Give me a sentence : ");
String string = SimpleIO.readLine();

int numChar=string.length();
char[] charArray=new char[numChar];
string.getChars(0, numChar, charArray,0);
int i=0,flag=0;
System.out.println("Your String before repalce\n"+string);
while(i<charArray.length)
{
if(charArray[i]=='a')
{
charArray[i]='e';
flag=1;
}
else if(charArray[i]=='e')
{
charArray[i]='i';
flag=1;
}
else if(charArray[i]=='i')
{
charArray[i]='o';
flag=1;
}
else if(charArray[i]=='o')
{
charArray[i]='u';
flag=1;
}
else if(charArray[i]=='u')
{
charArray[i]='a';
flag=1;
}
i++;
}
if(flag==1)
{
String newString=new String(charArray);
System.out.println(newString+"\n\nYour char has been replaced");
}
if(flag==0)
{
System.out.println("\nThe char not found");
}
}
}

Thanks


Related Tutorials/Questions & Answers:
Advertisements
 

 

 

DMCA.com