输入一串数字 找到最小值

编程入门 行业动态 更新时间:2024-10-09 13:31:25

输入一串数字 找到<a href=https://www.elefans.com/category/jswz/34/1768825.html style=最小值"/>

输入一串数字 找到最小值

朋友李老板 给我发了一篇全英文的java系题  看得眼睛都花了  在做的过程中第10题比较有趣 我写出来分享下

Write a complete Java program that prompts the user for a series of numbers to determine the smallest value entered.  Before the program terminates, display the smallest value.

 就是我标题的意思 

一拿到这个题我就想到了  我要做个数组  通过循环遍历来保存我keyboard输入的数字 ,  然后在来一个循环 遍历数组 挨个比较大小 。遇到比他小的 就把小的赋值给min变量 。后来在敲代码的过程中 我发现我的min 还需要一个初始值 而这个初始值不可以为零

因为为零的话 那么我的判断 就会认为0是最小的  于是我的min就恒为0;思考了半宿没想出好方法 ;第二天 ;李老板高兴的给我说他拿去问老师了  ;代码是

package lilaobanTEXT20180808;

 

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        ArrayList<Integer> arrayList = new ArrayList();
    int MIN = 0;
        
        System.out.println("How many numbers do you need to type in?");
        Scanner scanner = new Scanner(System.in);
        int getT

更多推荐

输入一串数字 找到最小值

本文发布于:2024-03-04 14:09:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1709474.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:最小值   数字

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!