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

 
 


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

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 Pages:

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.