首页 > 其他 > 详细

从控制台读取数据

时间:2020-03-26 20:25:43      阅读:46      评论:0      收藏:0      [点我收藏+]

从控制台读取一个数字


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

技术分享图片

从控制台读取数据

原文:https://www.cnblogs.com/alyiacon/p/12576824.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!