I'm trying to print ooed (changing the name from Fred to ooed), but my program won't change the first letter ('F') while changing the rest.
String name = "Fred";
String namea = name.replace('a', 'i');
String nameb = name.replace('n', 'i');
String namec = name.replace('r', 'o');
String named = name.replace('F', 'o');
for(int i =0; i < 4; i++){
switch(name.charAt(i)){
case 'a':
name = namea;
break;
case 'n':
name = nameb;
break;
case 'r':
name = namec;
break;
case 'F':
name = named;
break;
}
}
System.out.println(name);
Anyone know what I'm doing wrong?
Try using
contains
for comparisons, and make sure to differentiate the primitive data types.