我在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