我写了一个程序,用户将输入10个数字,最终这些数字将被存储在数组列表中。如何计算ArrayList中的最小数字?
当用户输入完数字后,我必须在ArrayList中找到最小的数字并打印出来。
我的代码:
package findingsmallestandbiggestnum;
import java.util.Scanner;
import java.util.ArrayList;
public class FindingSmallestAndBiggestNum {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
ArrayList<Integer> uInput = new ArrayList();
for (int i = 1; i <= 10; i++) {
System.out.println("Enter 10 numbers: ");
uInput.add(input.nextInt());
}
System.out.println("You have entered: " + uInput);
//calculate the smallest integer in the array
//for (int i = 0; i < uInput.length; i++) {
//}
}
}
你已经知道你想要的最小的数字。有一段时间,认为自己是电脑 - 如果给出10个数字,你会怎么去寻找最小的数字?一旦你有了,剩下的就落在原地。 :-) – 2014-12-05 15:55:31
附注:包名应清晰简洁。 – akaHuman 2014-12-05 15:55:43
你如何找到最低价值?当您对最小值/最大值感兴趣时,读取一系列无序数字时,您会做什么? – Pshemo 2014-12-05 15:57:18