举一反三
- 下面程序的运行结果( )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); } }
内容
- 0
下面程序的运行结果是 public class Test { public static void main(String[] 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[]) { 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 [ ][ ] 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);