System.out.println("Input the name of the student:");
String N=reader.nextLine();
System.out.println("Input the number of the student:");
int n=reader.nextInt();
我在跑这两句时,直接给我输出:
Input the name of the student:
Input the number of the student:
不给我机会输入姓名啊……
求助!!!
public static void main(String[] args){
Scanner reader = new Scanner(System.in);
System.out.println("Input the name of the student:");
String N=reader.nextLine();
System.out.println("Input the number of the student:");
int n=reader.nextInt();
}
在我ECLIPSE里面编译的是好的,第一行输入姓名,第二行输入数字。
首先检查一下Scanner是否是System.in
或者设断点看看N的值,是否被赋值。
我这边也运行正常,不知道楼主那边有没有报什么错误?以下是代码,希望对你有帮助。
package overloadtest; import java.util.Scanner; public class ThreadCooperation { public static void main(String[] args) { Scanner reader = new Scanner(System.in); System.out.println("Input the name of the student:"); String name = reader.nextLine(); System.out.println("Input the number of the student:"); int number = reader.nextInt(); System.out.println("name:" + name); System.out.println("number:" + number); } }
完整代码贴出来看下