最小值"/>
输入一串数字 找到最小值
朋友李老板 给我发了一篇全英文的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
更多推荐
输入一串数字 找到最小值
发布评论