I want to make a java program to replace spaces with % 20
. I was thinking of making a loop and when I find a " "
I replace the character with the three characters. However I have a problem with .charAt()
. In effect it seems that you can not change a character. Here is the error:
replaceSpaces.java:8: error: unexpected type
s.charAt(i)="%20";
^
required: variable
found: value
Here is the whole program:
public class replaceSpaces{
String s = "Hello Antoine";
public static void replaceSpaces(String s){
for(int i = 0;i<s.length();i++){
if(s.charAt(i)==' '){
s.charAt(i)="%20";
}
}
System.out.println(s);
}
}