我正在尝试编写一个程序,该程序将输入一个句子,然后输入两个字母,然后切换这些字母的所有实例,然后打印出切换后的句子。例如,他们可以输入
I like to eat bananas
然后是“e”和“a”,我的程序会打印
I lika to aet benenes
这是我的代码,但最后它会打印出字符串索引。任何想法如何解决这一问题?
System.out.println("Write something awesome.");
String input1 = Keyboard.readString();
System.out.println("Pick a letter from that awesome sentence.");
char letter1 = Keyboard.readChar();
System.out.println("Pick another letter from that awesome sentence.");
char letter2 = Keyboard.readChar();
double let1 = (input1.length());
int let1Next = (int) let1;
double let2 = (input1.length());
int let2Next = (int) let2;
String newUserImput = input1.replace(input1.charAt(let1Next),
input1.charAt(let2Next));
System.out.println(newUserImput);