循环获取控制台输入scanner.nextLine()问题

循环获取控制台输入scanner.nextLine()问题

直接上代码

public static void main(String[] args) {
    
    

        Scanner scanner = new Scanner(System.in);
        int i = scanner.nextInt();
        System.out.println(i);
        scanner.nextLine(); //需要加上这一行吸收上一行nextInt的回车
        for (int j = 0; j < 3; j++) {
    
    
            String s = scanner.nextLine();
            System.out.println(s);
        }
    }

》》》博主长期更新学习心得,推荐点赞关注!!!
》》》若有错误之处,请在评论区留言,谢谢!!!

猜你喜欢

转载自blog.csdn.net/qq_41622739/article/details/106395656
今日推荐