//求数组int a[] = {4,-1,9,10,23},最大值,并得到对应index public class test{ public static void main(String[] args) { int a[] = {4,-1,9,10,23},temp = 0 ,index = 0; for (int i = 0; i <= 3;i++){ if (a[i] < a[i+1]){ temp = a[i+1]; index = i + 1; } } System.out.print("该数组最大值 = " + temp + "\n该数组最大值的下标 = " + index); }; }