我遇到了兩個小的意外類型錯誤,我在嘗試解決時遇到了問題。發生在意外的類型錯誤
的錯誤:
swapped.charAt(temp1) = str.charAt(temp2);
swapped.charAt(temp2) = temp1;
有什麼建議?
public class SwapLetters
{
public static void main(String[] args)
{
System.out.println("Enter a string: ");
String str = new String(args[0]);
String swapped = str;
char[] charArray = str.toCharArray();
System.out.println("Enter a position to swap: ");
int Swap1 = Integer.parseInt(args[1]);
System.out.println("Enter a second position to swap: ");
int Swap2 = Integer.parseInt(args[2]);
char temp1 = str.charAt(Swap1);
char temp2 = str.charAt(Swap2);
swapped.charAt(temp1) = str.charAt(temp2);
swapped.charAt(temp2) = temp1;
System.out.println("Original String = " + str);
System.out.println("Swapped String = " + swapped);
}
}
你得到的錯誤是什麼 –
你看過編譯器有什麼要說的嗎? –
好ole lside vs rside – pamphlet