(4-3)写出以下程序运行结果。 public class Demo05 { public static void main(String[] args) { int temp = 0; int[][] arr = { { 3, 4, 5 }, { 7, 8, 2 }, { 1 }, { 6, 2, 8 } }; for (int[] list : arr) for (int x : list) { if(x>3) temp += list.length; } System.out.println(temp); } }
举一反三
- 下面程序的运行结果( )public class Demo{public static int fun(int c){return c+=2;}public static void main(String[] args){int temp=fun(2);System.out.println(temp);}} A: 2 B: 4 C: 6 D: 8
- (4-1)写出下面程序运行结果。 public class Demo5 { public static void main(String []args) { int[] arr={12,35,8,7,2}; Arrays.sort(arr); System.out.println(arr[3]*arr.length); } }
- (7-13)请阅读程序,写出程序运行结果。 //运行结果题 public class Demo4 { public static int print(Object obj) { int []arr; int sum=1; if(obj instanceof int[]) { arr=(int[])obj; for(int x:arr) { sum=arr.length+sum; } } return sum; } public static void main(String[] args) { int []arr= {1,2,3,4,5}; String [] list= {"孙悟空","猪八戒","唐僧"}; System.out.println(print(arr)+print(list)); } }
- 阅读下面程序,程序的运行结果是( )。public class Example {public static void main(String[] args) {int area = getArea(3, 5);System.out.println(" The area is " + area);}public static int getArea(int x, int y) {int temp = x * y; return temp; }} A: 编译错误 B: The area is 3 C: The area is 5 D: The area is 15
- 请阅读程序,然后写出程序运行结果。 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); } }