public class ArrayDemo1{ public static void main(String[] args){ //1 定义数组 并同时赋值 int[] arr = new int[]{3,9,5,8,2}; // 4 System.out.println(arr.length); System.out.println(arr[arr.length-1]); System.out.println("========================="); //2定义数组 直接用大括号赋值 int[] arr1 = {22,56,89}; System.out.println(arr1[arr1.length-1]); // 3 为数组赋值 arr1[2] = 111; System.out.println(arr1[arr1.length-1]); } } public class ArrayDemo2{ public static void main(String[] args){ //1 定义数组 并同时赋值 int[] arr = {3,9,5,8,2,87}; int max=arr[0]; for(int i=0;i<=5;i++){ //遍历 //System.out.println(arr[i]); if(max<arr[i]){ max=arr[i]; } } System.out.println(max); } }