从控制台读取数据

从控制台读取一个数字


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();
}

从控制台读取一串数字,可以是一行,也可以是多行,ctrl+c停止输入


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

posted @ 2020-03-26 19:45  L7UI  阅读(343)  评论(0)    收藏  举报