关于Java分行输入int值和String值
文章目录
`Scanner in=new Scanner(System.in);
Integer fistNum=in.nextInt();
String fuhao=in.nextLine();
Integer secondNum=in.nextInt();`
这里的输出会报错
解决方案:
可以创建两个输入对象
`Scanner in1=new Scanner(System.in);
Scanner in2=new Scanner(System.in);
Integer fistNum=in1.nextInt();
String fuhao=in2.nextLine();
Integer secondNum=in1.nextInt();`

评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论