java - Scanner 在 调用next是无法再输入时

解决办法 : 1 创建两次对象,但是浪费空间;


public class scannerdemo {

    public static void main(String[] args) {
        Scanner sc1 = new Scanner(System.in);
        sc1.nextInt();
        Scanner sc2 = new Scanner(System.in);
        sc2.nextInt();
    }
}

                  2 键盘录入都市字符串,都用nextLine方法.

public class scannerdemo {

    public static void main(String[] args) {
        Scanner sc1 = new Scanner(System.in);
        sc1.nextLine();
       // Scanner sc2 = new Scanner(System.in);
        sc1.nextLine();
    }
}

猜你喜欢

转载自blog.csdn.net/sulaymanyf/article/details/81139205
今日推荐