首页 新闻 赞助 找找看

Java新手求助

0
[待解决问题]

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:

不给我机会输入姓名啊……

求助!!!

August sky的主页 August sky | 菜鸟二级 | 园豆:202
提问于:2013-10-08 21:05
< >
分享
所有回答(3)
0

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的值,是否被赋值。

Monster_Ch | 园豆:202 (菜鸟二级) | 2013-10-08 22:05
0

我这边也运行正常,不知道楼主那边有没有报什么错误?以下是代码,希望对你有帮助。

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);
    }
}
View Code
beyondchina | 园豆:680 (小虾三级) | 2013-10-29 11:41
0

完整代码贴出来看下

flab | 园豆:208 (菜鸟二级) | 2014-05-06 12:54
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册