import java.util.Scanner;
public class StringLength {
private Scanner scan = new Scanner(System.in);
public static void main(String[] args) {
StringLength sl = new StringLength();
sl.scanMany();
}
public void scanMany() {
System.out.print("Enter update user id: ");
int id = scan.nextInt();
System.out.print("Enter update name: ");
String name = scan.nextLine();
System.out.print("Enter update password: ");
String password = scan.nextLine();
System.out.println(id + "\t\t" + name + "\t\t" + password);
}
}
运行结果如下:
Enter update user id: 11
Enter update name: Enter update password: 56
11 56
第二个参数 name 系统居然不让输入了是怎么回事 ?
------解决方案--------------------------------------------------------
sorry!是我搞错了.
public void scanMany() {
System.out.print("Enter update user id: ");
int id = scan.nextInt();
scan = new Scanner(System.in);
System.out.print("Enter update name: ");
String name = scan.nextLine();
System.out.print("Enter update password: ");
String password = scan.nextLine();
System.out.println(id + "\t\t" + name + "\t\t" + password);
}
把scan重新赋值就可以啦.