我收到扫描仪错误

时间:2013-06-13 16:46:10

标签: java

我从命令提示符处收到此错误:

bikeGame.java:9: error: cannot find symbol
     String input = scanner.nextLine();
                    ^
symbol:   variable scanner
location: class bikeGame
1 error

您好,在收到上述错误时,您能帮我解决一下吗? (我是java新手,如果你能看到错误,这是我的代码)

import java.util.Scanner;
import java.io.IOException;
class bikeGame {
 public static void main(String[] args){

 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>");

 float b;
 float c;
 float d;

 boolean brakes = false;
 byte speed = 5;
 byte gear = 1;

 Scanner myScanner = new Scanner(System.in);

 b = myScanner.nextFloat();
 c = myScanner.nextFloat();
 d = myScanner.nextFloat();

 }
}

1 个答案:

答案 0 :(得分:5)

您似乎没有宣布第一个scanner

 Scanner scanner = new Scanner(System.in);
 String input = scanner.nextLine();