package text4;
public class demo {
public static void main(String[] args) {
int[] arr = new int[4];
arr[0] = 5;
arr[1] = 3;
arr[2] = 8;
arr[3] = 9;
int max = arr[0];
int n = 0;
for (int i = 1; i < arr.length; i++) {
if (arr[i] > max) {
max = arr[i];
n = i;
}
}
System.out.println("最大值為:" + max + "下標為:" + n);
}
}
静态初始化 :定义数组的同时就为 数组赋值
动态初始化:只指定数组的长度,有系统为数组赋初始值