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);}}请写出运行结果
举一反三
- 中国大学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]
- 请阅读程序,然后写出程序运行结果。 public class Demo7 { public static void main(String[] args) { int [] arr= new int[5]; int sum=0; Arrays.fill(arr, 3); for(int x:arr) { sum=sum+x; } System.out.println(sum); } }
- 下面代码的运行结果是_____________。 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]
- 请阅读下面的程序 Public class Test { public static void main(String[] args) { int a = 0; int b = 0; for (int i = 1; i <= 5; i++) {