int id;
float grade;
String name;
Scanner z= new Scanner(System.in);
System.out.println("Give the id:\n");
id=z.nextInt();
System.out.println("your id is :"+id+"\n");
System.out.println("Give the name:");
name=z.nextLine();
System.out.println("your name is :"+name);
System.out.println("Give the grade:\n");
grade=z.nextFloat();
的問題是這樣this.It輸入整數,但是當涉及到字符串,它打印「給命名爲」但直到我輸入的東西它不等待,它跳過到下一條指令。跳過輸入查詢字符串
這是爲什麼?
請參閱http://stackoverflow.com/questions/19485407/user-input-string-and-integers-in-java/19485423#19485423 –