ROTATE THE VOWELS IN A STRING!!!

ROTATE THE VOWELS IN A STRING!!!

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:

Ads