阅读下面程序,程序的运行结果是( )。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
A: 编译错误
B: The area is 3
C: The area is 5
D: The area is 15
举一反三
- 下列程序的输出结果为 class Box{ int length,width,height; public void setInfo(int l,int w,int h){ length = l; width = w; height = h; } public int volumn(){ return length*width*height; } public int area(){ return (length*width + length*height + width*height) * 2; } public String toString(){ return "Length:" + length + " width:" + width + " height:" + height + " volumn: " + volumn() + " area:" + area(); }} public class BoxTest { public static void main(String[] args) { Box b = new Box(); b.setInfo(5,2,4); System.out.println(b.toString()); }}
- 下面程序的运行结果( )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
- 下面程序的运行结果是 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); } }
- (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 MyClass{ private static int a = 19; public static void modify(int a){ a = a + 5;} public static void main(String[] args){ modify(a); System.out.println(a); }}