只是想知道你們是否可以幫助我解決這個錯誤我一直在嘗試 修復過去一小時左右。必需:沒有參數,找到:字符串
我打電話這段代碼有錯誤的功能:
static Scanner scan = new Scanner(System.in);
static int xIn, yIn;
static String name = "";
static String input = "";
public static void main(String[] args){
if(args.length < 2){
System.out.println("Not enough arguments. Temination.");
System.exit(0);
}
else if(args.length > 2){
System.out.println("Too many arguments. Termination.");
System.exit(0);
}
BottyBot.Test(Integer.parseInt(args[0]), Integer.parseInt(args[1]));
BottyBot.Greet();
}
而且BottyBot.Greet()函數是:
public static void Greet(){
name = scan.nextLine("Hello, what is your name? ");
do{
input = scan.nextLine("Would you like to order some boots, " + name + "? (y/n) ");
if(input == "y"){
System.out.println("Great! Let's get started.");
break;
}
else if(input == "n"){
System.out.println("Come back next time, " + name + ".");
System.exit(0);
}
else{
System.out.println("Invalid response. Try again.");
}
}
while(true);
}
我得到兩個錯誤的兩個掃描儀線。具體而言,這是說
error: method nextLine in class Scanner cannot be applied to given types;
next = scan.nextLine("Hello, what is your name? ");
^
required: no arguments
found: String
reason: actual and formal argument lists differ in length
如果有人能指出我在做什麼錯了,這將是偉大的!謝謝!
'Scanner.nextLine()'不帶參數。你提供了一個參數。你在做什麼是錯誤的,編譯器告訴你。 – Kayaman
由於錯誤清楚地說..有沒有參數'nextLine()' –