以下代码的输出结果?public class Test{public static void main(String argv[]){String x="hello";change(x);System.out.println(x);}static void change(String m){m=m+2;}}
A. hello
B. hello2
C. 编译报错
D. 运行报错,不能将串与整数相加
查看答案
假设a是int类型变量,并初始化为1,则下列哪个为合法的条件语句?
A. if (a) { }
B. if (a<<3、{ }
C. if (a= 2、{ }
D. if (true) { }
设有如下类:
class MyPoint {
void myMethod() {
int x, y;
x = 5; y = 3;
System.out.print(" (" + x + ", " + y + " ) " );
switchCoords(x, y );
System.out.print(" (" + x + ", " + y + " ) " );
}
void switchCoords(int x, int y ) {
int temp;
temp = x;
x = y;
y = temp;
System.out.print(" (" + x + ", " + y + " ) " );
}
}
如果执行myMethod()方法,则输出结果为?
A. (5, 3、(5, 3、(5, 3、
B. (5, 3、(3, 5、(3, 5、
C. (5, 3、(3, 5、(5, 3、
设有如下类
class Loop{
public static void main(String[] agrs) {
int x=0;int y=0;
outer:
for(x=0;x<100;x++){
middle:
for(y=0;y<100;y++){
System.out.println("x="+x+"; y="+y);
if(y==10){<<>>}
}
}
}
}
在<<>>处插入什么代码可以结束外循环?
A. continue middle;
B. break outer;
C. break middle;
D. continue outer;
E. none of these
以下程序的运行结果为:public class A {static int k=3;public static void main(String[] args) {int k=4;A x1=new A();x1.k++;A x2=new A();x2.k++;k++;System.out.println(x1.k);}}
A. 3
B. 4
C. 5
D. 6
E. 7