输出数组中最大值
public class ArrToBig {
public static void main(String[] args) {
int[] arr={-3,-6,-3,-10,-5,-4,2};
int index = 0;
for (int i=0;i< arr.length ; i++){
index = (arr[index] <= arr[i]) ? i : index ;
}
System.out.println("最大值为:"+arr[index]);
}
}
输出数组中最大值下标
public class ArrToBigIndex {
public static void main(String[] args) {
int[] arr={-3,-6,-3,-10,-5,-4,2};
int index = 0;
for (int i=0;i< arr.length ; i++){
index = (arr[index] <= arr[i]) ? i : index ;
}
System.out.println("最大值的下标为:"+index);
}
}
输出数组中最小值
public class ArrToNoBig {
public static void main(String[] args) {
int[] arr={-3,-6,3,-10,-5,-4,-2};
int index = 0;
for (int i=0;i< arr.length ; i++){
index = (arr[index] >= arr[i]) ? i : index ;
}
System.out.println("最小值为:"+arr[index]);
}
}
输出数组中最小值下标
public class ArrToNoBigIndex {
public static void main(String[] args) {
int[] arr={-3,-6,3,-10,-5,-4,-2};
int index = 0;
for (int i=0;i< arr.length ; i++){
index = (arr[index] >= arr[i]) ? i : index ;
}
System.out.println("最小值的下标为:"+index);
}
}