package index;
//取出int数组中的最大值及下标
import java.util.Arrays;
import javax.naming.InitialContext;
public class Test {
public static void main(String[] args) {
int[] arr = { 0, 45, 14, 85, 12, 14, 7, 25, 85, 14, 555, 111, 222, 51, 785, 2, 36 };
int max = 0;
int maxIndex = 0;
for (int i = 0; i < arr.length; i++) {
if (arr[i] > max) {
max = arr[i];
maxIndex = i;
}
}
System.out.println(max + "----" + maxIndex);
}
}
//取出集合中最大值 ,最小值
public static void main(String args[])
{ //Double[] num = { 45.1,45.2 };
List dlist=new ArrayList();
dlist.add(45.1);
dlist.add(45.2);
dlist.add(110.22);
Double max = (Double)dlist.get(0);
Double min = (Double)dlist.get(0);
for (int i = 0; i < dlist.size(); i++) {
if (min > (Double)dlist.get(i)) min = (Double)dlist.get(i);
if (max < (Double)dlist.get(i)) max = (Double)dlist.get(i);
}
System.out.println("max的值为" + max + "min的值为" + min);
}