我一直在尝试使用java.util.scanner,我收到错误,你能帮帮忙......
The error as said in Command Prompt:
18: error :cannot find simbol
if (answer.equalsignoreCase("yes));
^
symbol: variable answer
这是我从命令提示符获得的错误,这是我写的代码:
import java.util.Scanner;
import java.io.IOException;
class bikeGame {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
boolean brakes = false;
byte speed = 5;
byte gear = 1;
String start = " Your current speed is 5km/h. You are in the first gear.";
String welcome = "Welcome to Bike Rider! You can use the commands 'faster', 'slower' and 'brakes'. Type 'start' to begin...";
String die = "You died, type 'start' to play again...";
System.out.println(welcome);
String input = scanner.nextLine();
System.out.println("You selected " + input + "? Is this correct? <true or false>");
if (answer.equalsgnoreCase("yes"));
System.out.println(start);
float b;
float c;
float d;
Scanner myScanner = new Scanner(System.in);
b = myScanner.nextFloat();
c = myScanner.nextFloat();
d = myScanner.nextFloat();
}
}
如果您发现问题,请随时回答......
答案 0 :(得分:2)
您尚未声明变量answer
,但已使用它:
if (answer.equalsgnoreCase("yes"));
也许,您想将input
命名为answer
?
<强> P.S。 :不是.equalsgnoreCase()
,而是.equalsIgnoreCase()
。