Java键盘输入字符串问题
privateintnum;privateStringname;privateintjava;privateintweb;privateintdba;publicvoid...
private int num;
private String name;
private int java;
private int web;
private int dba;
public void Shuru(){
Scanner in = new Scanner(System.in);
System.out.print("学号为:");
num = in.nextInt();
System.out.print("姓名为:");
String name = in.nextLine();
System.out.print("Java成绩为:");
java = in.nextInt();
System.out.print("网页成绩为:");
web = in.nextInt();
System.out.print("数据库成绩为:");
dba = in.nextInt();
其他的都可以正常输入,但是到输入姓名的时候就会直接跳过,求高手指点!!!!!!!!!!! 展开
private String name;
private int java;
private int web;
private int dba;
public void Shuru(){
Scanner in = new Scanner(System.in);
System.out.print("学号为:");
num = in.nextInt();
System.out.print("姓名为:");
String name = in.nextLine();
System.out.print("Java成绩为:");
java = in.nextInt();
System.out.print("网页成绩为:");
web = in.nextInt();
System.out.print("数据库成绩为:");
dba = in.nextInt();
其他的都可以正常输入,但是到输入姓名的时候就会直接跳过,求高手指点!!!!!!!!!!! 展开
2个回答
展开全部
private int num;
private String name;
private int java;
private int web;
private int dba;
public void shuru(){
Scanner in = new Scanner(System.in);
System.out.print("学号为:");
num = in.nextInt();
System.out.print("姓名为:");
name = in.next();
System.out.print("Java成绩为:");
java = in.nextInt();
System.out.print("网页成绩为:");
web = in.nextInt();
System.out.print("数据库成绩为:");
dba = in.nextInt();
}
输入姓名用in.next(),用in.nextLine()就跑到下一行去了。
private String name;
private int java;
private int web;
private int dba;
public void shuru(){
Scanner in = new Scanner(System.in);
System.out.print("学号为:");
num = in.nextInt();
System.out.print("姓名为:");
name = in.next();
System.out.print("Java成绩为:");
java = in.nextInt();
System.out.print("网页成绩为:");
web = in.nextInt();
System.out.print("数据库成绩为:");
dba = in.nextInt();
}
输入姓名用in.next(),用in.nextLine()就跑到下一行去了。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询