为什么它向读者显示错误?我还试着导入阅读器

  • 本文关键字:导入 错误 显示 java reader
  • 更新时间 :
  • 英文 :


我的代码:

import java.util.Scanner;
import java.io.Reader;    #I also tried to do this, it didnt help
public class firstClass {
public static void main(String[] args) {  
System.out.println("how many player?");  #this output works if I delate the reader in the line
int a = reader.nextInt();                #for some reason it shows error for reader
}
}

错误:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
reader cannot be resolved
at firstClass.main(firstClass.java: 7)

而且如果我只是删除阅读器的行,它也不会显示任何错误

import java.util.Scanner;
class Main { 

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in); 

System.out.println("Enter your name");
String name = scanner.nextLine();
System.out.println("your name is " + string); 

System.out.println("Enter your age");    
int number = scanner.nextInt();
System.out.println("Your age is " + number);     
}
}

要编译,请在您的终端上写:

javac Main.java

要运行,请在您的终端上写入:

java Main

相关内容

  • 没有找到相关文章

最新更新