我在java的初學者,我在做什麼practiceit問題關閉internet.I試圖嘗試的問題,但我不明白的錯誤。生成反向話
編寫一個名爲processName的方法,該方法接受控制檯的掃描儀作爲參數,並提示用戶輸入其全名,然後以相反順序(即姓氏,名字)打印名稱。你可能會認爲只會給出第一個和最後一個名字。你應該用掃描儀讀取輸入的整條生產線一次,然後根據需要打破它分開。下面是與用戶的樣本對話:
請輸入您的全名:薩米Jankis 你按相反的順序名字是Jankis,薩米
public static void processName(Scanner console) {
System.out.print("Please enter your full name: ");
String full=console.nextLine();
String first=full.substring(0," ");
String second=full.substring(" ");
System.out.print("Your name in reverse order is: "+ second + "," + first);
}
也許我會去解釋我的code.So我嘗試打破這兩個詞apart.So我使用的串找到這兩個詞,然後我硬編碼扭轉他們。我認爲邏輯是正確的,但我仍然得到這些錯誤。
Line 6
You are referring to an identifer (a name of a variable, class, method, etc.) that is not recognized. Perhaps you misspelled it, mis-capitalized it, or forgot to declare it?
cannot find symbol
symbol : method substring(int,java.lang.String)
location: class java.lang.String
String first=full.substring(0," ");
^
Line 7
You are referring to an identifer (a name of a variable, class, method, etc.) that is not recognized. Perhaps you misspelled it, mis-capitalized it, or forgot to declare it?
cannot find symbol
symbol : method substring(java.lang.String)
location: class java.lang.String
String second=full.substring(" ");
^
2 errors
33 warnings
子不能把字符串參數作爲第二參數。 substring(int,int)是正確的。你給出的是substring(int,String,這是錯誤的。 – AmitG 2013-03-09 16:25:00
你的意思是bth參數必須是相同的?如果它是int,那麼這兩個參數必須是int? – user2148463 2013-03-09 16:27:10