-5

我一直在尝试使用 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();



 }
}

如果您看到问题,请不要犹豫,回答...

4

1 回答 1

2

您尚未声明变量answer,但使用了它:

if (answer.equalsgnoreCase("yes"));

也许,你想命名inputanswer

PS:不是.equalsgnoreCase(),是.equalsIgnoreCase()

于 2013-06-14T12:08:11.560 回答