I have to fix programme where the programme asks the user for an input of a random text.

When the text is written in the programme will change specific letters like a to be c so
I am a man would be I cm c mcn

public static void main(String[] args){
Scanner user_input = new Scanner (System.in);

"
String text;
System.out.print("enter a text!");
text = user_input.next();
String newText = text.replace('d', 'l');   

System.out.println( "new = " + newText ); 

 }
}
"

When i write in my text it dosent change the output for example.

Input: I dont like donuts
the programme will print out "i lont like lonuts.

It will simply change all d to l and print out the input the user wrote.

ehm... is that what it is doing, or what it is supposed to do?
I'm still not really clear on what your issue is.
it seems to work, so I don't get what you are trying to ask.

Edited 3 Years Ago by stultuske

When i run this programme it prints out the input taste but it keeps it original, it dosent replace the speficic letters im trying to programe it to you.

Basically its supposed to prompt the user to write a random text, then if the text contains one kind of letter it will change it, i.e change all a's to x's

But as it is now it only prints out the text but dosent change the letters.

This is what happens when i run it in jdeveloper, do you know what might be causing it not to work properly for me?

Attachments question.png 92.9 KB

I managed to solve it now. I had to make the last line

text =text.replace('m', 'x');

The code you were executing wasn't the code you originally posted. The posted code was OK, the code you ran was wrong. You just wasted a whole load of people's time.

Edited 3 Years Ago by JamesCherrill

This article has been dead for over six months. Start a new discussion instead.