0
whats wrong?
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scan = new Scanner (System.in); String x = scan.nextLine(); x.replace ("o" , "p"); System.out.println (x); } }
3 Respuestas
+ 4
replace doesn't change the original string, it returns a modified version of that string.
x = x.replace("o","p"); should work.
+ 1
String are immutable.. Read about that topic..
And if you need replaced result.. You need to save result by replace like
x=x.replace("o","p");
This only replace first occurrence of "o",
For all, use
x=x. replaceAll("o", "p") ;
0
Kevin Star thanks!