System.out.print("Name : ");
String name = in.nextLine();
System.out.print("Age : ");
int age = in.nextInt();
System.out.print("City : ");
String city = in.nextLine();
输出将是:用户输入的字符串和整数在Java中
名称:测试
年龄:20
生成成功
当我进行调试,它赢得了”阅读“城市”的用户输入。但是当我将“年龄”的数据类型更改为字符串时,它会读取。我怎样才能使系统读取城市用户输入的数据类型为int?
@ athirahhazira94,你已经经历关于nextLine()。 Anda kena baca tentang nextLine()。 – gjman2