import java.util.Random; class zuoye { public static void main(String[] args) { //随机点名 /*String[] arr = {"董斌","张锐","王荣臣","韩凯","张禄","刘继勋","张维","牛攀","魏中豪"}; for(int i = 0;i<arr.length;i++){ System.out.println(arr[i]); } Random r = new Random(); int i = r.nextInt(9); System.out.println(arr[i]);*/ //数组的概念?有什么特点? //概念:一组数据的集合,数组中的每个数据被称作元素 //特点:数组中可以存放任意类型的元素,但同一个数组里存放的元素类型必须一致 //一维数组的定义格式? //数据类型[] 数组名 = new 数据类型[元素个数或数组长度]; //类型[] 数组名 = {元素,元素,元素,……}; //数组操作的两个小问题? //数组越界异常 //空指针异常 //数组遍历最大值 int[][] arr1 = {{12,13},{15,16,17},{18,99,66}}; int max = arr1[0][0]; int min = arr1[0][0]; /*for(int i = 0;i<arr1.length;i++){ for(int j = 0;j<arr1[i].length;j++){ if(arr1[i][j]>=max){ max = arr1[i][j]; } } } System.out.println(max);*/ /*for(int i = 0;i<arr1.length;i++){ for(int j = 0;j<arr1[i].length;j++){ if(arr1[i][j]<=min){ min = arr1[i][j]; } } } System.out.println(min);*/ //数组逆序 /*for(int i = arr1.length-1; i>=0; i--){ for(int j = arr1[i].length-1; j>=0; j--){ System.out.println(arr1[i][j]); } }*/ //题目 二维遍历及求和 int[][] arr2 = {{22,66,44},{77,33,88},{25,45,65},{11,66,99}}; for(int i = 0;i<arr2.length;i++){ for(int j = 0;j<arr2[i].length;j++){ System.out.println(arr2[i][j]); } } System.out.println(); int sum = 0; int sum1 = 0; for(int i = 0;i<arr2.length;i++){ for(int j = 0;j<arr2[i].length;j++){ sum+=arr2[i][j]; sum1+=arr2[i][j]; } System.out.println("第"+(i+1)+"季度销售额:"+sum1); sum1 = 0; } System.out.println("总销售额为:"+sum); } }