Reads the data from the console

A number is read from the console


public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    String str = s.nextLine();
    int n = Integer.parseInt(str);
    // int n = s.nextInt();
}

Reading the series of numbers from the console, it can be one, or may be multi-line, ctrl + c stop input


public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    ArrayList<Integer> list = new ArrayList<>();
    while (s.hasNextInt())
        list.add(s.nextInt());
}

Guess you like

Origin www.cnblogs.com/alyiacon/p/12576824.html