中国大学MOOC: 已知:class C { public static void main(String[] args) { int[] array = new int[10]; increase(array); System.out.print(array[0]); } public static void increase(int[] array) { for(int i = 0; i < array.length; i++) { array[i]++; } }}则输出为[/i]
举一反三
- 中国大学MOOC: class C { public static void main(String[] args) { int[] array = new int[10]; increase(array); System.out.print(array[0]); } public static void increase(int[] array) { for(int i = 0; i < array.length; i++) { array[i]++; } }}则输出为[/i]
- 下面代码的输出是什么? int [][] array = {{1, 2},{3, 4},{5,6}}; int sum = 0; for(int i = 0; i < array.length; i++) sum = sum + array[i][0]; System.out.println(sum);[/i]
- public class Array1{public static void main(String[] args) {int odd = 0, even = 0;int[] array = new int[] { 1, 4, 7, 8, 9, 10, 0, 0, 14, 19, 24, 29 };for (int i : array) {if (i % 2 == 0) {even++;}else{odd++;}}System.out.printf("偶数=%d,奇数=%d", even, odd);}}请写出运行结果
- 下面代码的运行结果是_____________。 public class Test{ public static void main(String[] args){ int[] a=new int[3]; int[] b= new int[]{1,2,3,4,5}; a=b; for(int i=0; i<b.length; i++){ System.out.print(a[i]+" "); } } }[/i]
- 设int[] array=new int[5]{11,12,13,14,15};以下语句不能实现数组元素输出的是( ) A: foreach( int i in array){ Console.Write(i+ );} B: for( int i=0;iarray.Length();i++){ Console.Write(array[i]+ );} C: for( int i=0;iarray.GetLength(0);i++){ Console.Write(array[i]+ );} D: for( int i=0;iarray.Length;i++){ Console.Write(array[i]+ );}