维数组对象 在使用new新增数组时一并指定初始值 int[] score= new int[]{90,85,55,94,77}; for(int i=0; i score length; i++) System. out. printf("score[od] =od\n", i, score [i])i code\cho5\SimpleArray2,java
一维数组对象 • 在使用new新增数组时一并指定初始值 int[] score = new int[] {90, 85, 55, 94, 77}; for(int i = 0; i < score.length; i++) System.out.printf("score[%d] = %d\n", i, score[i]); code\ch05\SimpleArray2.java
维数组对象 可以使用动态的方式来宣告数组长度,而 不用在程序中事先决定数组大小 int length scanner. nextInt( f1at[] score= new float[ length];/动态配置长度 for(int i =0; i< score. length; i++)i System.out. print("输入分数:") float input scanner.nextFloato)i score[i]= inputi code\ch05\AverageInput java
一维数组对象 int length = scanner.nextInt(); float[] score = new float[length]; //动态配置长度 for(int i = 0; i < score.length; i++) { System.out.print("输入分数:"); float input = scanner.nextFloat(); score[i] = input; } • 可以使用动态的方式来宣告数组长度,而 不用在程序中事先决定数组大小 code\ch05\AverageInput.java
二维数组对象 维数组使用「名称」与「两个索引」来 指定存取数组中的元素 int[l[arr {{1,2,3} 4,5,6}} for(int i=0;i< arr length; i++) for(int j=0;j< arr[o]. length; j++) System. out. print(arr[i][j] + )i System. out. printin()i codecho5TwoDimArra lava 以对象的方式来配置一个二维数组对象 int[[ arr new int[2[3]i
二维数组对象 • 二维数组使用「名称」与「两个索引」来 指定存取数组中的元素 • 以对象的方式来配置一个二维数组对象 int[][] arr = {{1, 2, 3}, {4, 5, 6}}; for(int i = 0; i < arr.length; i++) { for(int j = 0; j < arr[0].length; j++) System.out.print(arr[i][j] + " "); System.out.println(); } int[][] arr = new int[2][3]; code\ch05\TwoDimArray. java
二维数组对象 以对象的方式来配置一个二维数组对象 int[ arr new int[2][3] int型態参考名稱 nt型態物件 arr[o] [2] arr int型態参考名稱 arr[1] in型態物件 int口型態物件 [2]
二维数组对象 • 以对象的方式来配置一个二维数组对象 int[][] arr = new int[2][3];