• 2021-04-14
    (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); } }
  • 18

    内容

    • 0

      下面程序的运行结果是 public class Test { public static void main(String&#91;&#93; args) { int temp = 0; for (int i = 1; i < 5; i++) { for (int j = 0; j < i; j++) { temp++; } } System.out.println(temp); } }

    • 1

      以下程序运行结果是 public class Test { public static void main(String[] args) { int a=1,b[]={2}; add(a); add(b); System.out.println(a+","+b[0]); } static int add(int x){ x++; return x; } static void add(int[] x){ x[0]++; } }

    • 2

      (6-9)请阅读程序,写出程序运行结果。 class Phone{ private String name; private int price; public Phone(String name, int price) { this.name = name; this.price = price; } public String toString() { return ""+this.price; } } public class PhoneDemo { public static void main(String[] args) { StringBuffer sb=new StringBuffer(); Phone [] list=new Phone[3]; list[0]=new Phone("华为",3000); list[1]=new Phone("小米8",4000); list[2]=new Phone("vivo R10",2300); for(Phone p:list) sb.append(p); System.out.println(sb.toString()); } }

    • 3

      写出以下程序的运行结果public class E4_1{ public static void main(String args&#91;&#93;) { int a = 1; int b = 2; int c = 3; a += 5; b *= 4; c += a * b; c %= 6; System.out.println("a = " + a); System.out.println("b = " + b); System.out.println("c = " + c); }}a=______ ,b=______ ,c=______ .

    • 4

      (4-3)初始了如下二维数组,( )能够遍历该二维数组。 int &#91; &#93;&#91; &#93; arr={{3,4,5},{7,8,2},{1},{6,2,8}}; A: for(int i=0;i for(int j=0;j System.out.println(arr[i][j]); B: for(int i=0;i for(int j=0;j System.out.println(arr[i][j]); C: for(int i=0;i for(int x:arr[i]) System.out.println(x); D: for(int list:arr) for(int x:list) System.out.println(x); E: for(int[ ] list:arr) for(int x:list) System.out.println(x);