正确,尽管变量var2定义了两次,但程序自动将它们看成一个变量;
正确,前面出现的变量var2有效期仅在if中,不会与后面的变量var2重叠 ;
错误,if 块中的变量var2有效期从这里直到函数结束,因此会出现变量重叠;
错误,不管变量在哪里定义,它们都会在函数入口处初始化,因此会出现变量重叠;
第1题:
下面程序的运行结果是( )。 public class Test { public static void main (String args[]) { int c=5; System. out. println (C); System. out. println (c++); System. out. println (C); } }
A.5 6 6
B.5 5 6
C.6 7 7
D.6 6 6
第2题:
A.正确,尽管变量var2定义了两次,但程序自动将它们看成一个变量;
B.正确,前面出现的变量var2有效期仅在if中,不会与后面的变量var2重叠;
C.错误,if块中的变量var2有效期从这里直到函数结束,因此会出现变量重叠;
D.错误,不管变量在哪里定义,它们都会在函数入口处初始化,因此会出现变量重叠;
第3题:
执行下列程序段之后,变量b的值为( )。 public class Test { public static void main (String[] args) { int i = 12; int j = 24; boolean b1 = true; booleanb=(j%i==0)&&(! b1) || (j/i! =2); System. out. println (B); } }
A.true
B.false
C.0
D.1
第4题:
下面代码的运行结果是( )。 public class ConcatTest { public static void main (String[ ] args) { String str1 = "abc"; String str2 = "ABC"; String str3 = str1. coneat(str2); System. out. println(str3); } }
A.abc
B.ABC
C.abcABC
D.ABCabc
第5题:
请将下面程序补充完整。
public class PowerCalc{
public static void main(String[]args){
double x=5.0;
System. out. println(x+"to the power 4 is"+power(x, 4));
System. out. println("7. 5 to the power 5 is"+power(7.5, 5));
System. out. println("7.5 to the power 0 is"+power(7.5, 0));
System. out. println("10 to the power -2 is"+power(10, -2));
}
static double【 】 (double x, int n){
if(n>1)
return x * power(x, n-1);
else if(n<0)
return 1.0/power(x, -n);
else
return n==0 ? 1.0:x;
}
}
第6题:
阅读以下说明和JAVA 2代码,将应填入(n)处的字句写在对应栏内。
[说明]
以下程序为类类型的变量应用实例,通过异常处理检验了类CCircle的变量的合法性,即参数半径应为非负值。仔细阅读代码和相关注释,将程序补充完整。
[JAVA代码]
//定义自己的异常类
class CCircleException extends Exception
{
}
// 定义类 CCircle
class CCircle
{
private double radius;
public void setRadius ( double r ) (1)
{
if ( r<0 ) {
(2)
}
else
(3)
}
Public void show ( ) {
System. out. println ( "area="+3.14*radius*radius );
}
}
public class ciusample
{
public static void main ( String args[] )
{
CCircle cir=new CCircle( );
(4) {
cir. setRadius ( -2.0 )
}
(5)
{
System. out. println ( e+" throwed" ) ;
}
cir. show( ) ;
}
}
第7题:
有如下代码段 public class OperatorAndExceptions { public static void main(String args[ ] { int i=10,j=15; System.out.println(i==j); String s1 = new String("how are you!"); String s2=new String("how are you!"); System.out.println(s1==s2); } } 其输出为( )。
A.true false
B.true true
C.false true
D.false false
第8题:
下列程序段的输出是( )。 public class Test { public static void main (String args[ ]) { String ss1 = new String("hello"); String ss2 = new String("hello"); System.out.println(ssl == ss2); System.out.println (ssequals(ss2)); } }
A.true, false
B.true, true
C.false, true
D.false, false
第9题:
下面的语句片段中,变量result结果为( )。 public class Test { public static void main (String args[ ]) { int sum=0; int r=2; iht result=(sum==1?sum:r); System. out. println (result); } }
A.1
B.2
C.10
D.0
第10题:
下列代码的执行结果是( )。 public class Test1 { public static void main(String args []) { float t=0f; int q=5; System. out. println((t++)*(--q)); } }
A.40
B.40
C.36
D.36
第11题:
给出下面程序: public class ex51 { public static void main(String[] args) { String s = "hello"; String t = "hello"; char c[] = {'h', 'e', '1', '1', 'o'}; System. out. println (______) } } 在程序的横线处填入下列______选项后,程序输出的结果是true。
A.t.equals(c)
B.s.equals?
C.s == t
D.t == c
第12题:
下面的代码是否有错误?() If (true) { String var2=”变量2”; System .out.println(var2); } String var2=”变量2B”; System .out.println(var2);
第13题:
A、inti=0;if(i){System.out.println(“Hi”);}
B、booleanb=true;booleanb2=true;if(b==b2){System.out.println(“Sotrue”);}
C、inti=1;intj=2;if(i==1||j==2)System.out.println(“OK”);
D、inti=1;intj=2;if(i==1
第14题:
执行下列代码段之后,变量b的值为______。 public class ex40 { public static void main(String[] args) { byte x=5; byte y=5; byte c=10; boolean b; b-c<x<<y; System.out.println (b); } }
A.1
B.0
C.false
D.true
第15题:
假设变量sum=0和j=80都是int类型,则下列语句中的正确的是( ).
A.if (true) System. out. println("true"); else;
B.if (5<>1) System. out. println( "not equal" );
C.for (iht j=20;j<<50;j--) System. out. println (j);
D.while (j>>=50) sum +=j; j--;
第16题:
执行下列程序段之后,变量n的值为( )。 public class Test { public static void main(String[ ] args){ int y = 2; int z = 3; int n = 4; n=n+-y* z/n; System. out. println(n); } }
A.3
B.-1
C.-12
D.-3
第17题:
下列代码的执行结果是( )。 public class Test{ public static void main String args[]){ String s1=new String("welcome"); String s2=new String("welcome"); System.out.println(s1==s2); System.out.println(s1.equals(s2)); } }
A.false,false
B.false,true
C.true,true
D.true,false
第18题:
下列代码段的执行结果是( )。 public class Test { public static void main(String args[ ]) { String s1= new String("hello"); String s2= new String("hello"); System.out.println(s1==s2); System.out.println(s1.equal(s2)); } }
A.true false
B.true true
C.false true
D.false false
第19题:
假设有String a = "A"; char b ='A'; int c=65,下面选项中正确的是( )。
A.if(a == b) {System. out. print("Equal") }
B.if(c == b) {System. out. print("Equal") }
C.if(a == c) {System. out. print ("Equal") }
D.if(c = b) {System. out. print("Equal") }
第20题:
下列代码的执行结果是______。 public class ex55 { public static void main(String args[] ) { String s1=new String("hello"); String s2=new String("hello"); System.out.print (s1==s2); System.out.print (","); System.out.println (s1.equals (s2)); } }
A.true, false
B.true, true
C.false, true
D.false, false
第21题:
已知如下代码: switch(m) { case 0: System. out. println("Condition 0 "); case 1: System. out. println("Condition 1 "); case 2: System. out. println("Condition 2 "); case 3: System. out. println("Condition 3 "); break; default: System. out. println("Other Condition"); 当m的值为( )时,可以输出“Condition 2”。
A.2
B.0,1
C.0,1,2
D.0,1,2,3
第22题:
当执行下面代码时,会输出( )。 Boolean b1 = new Boolean(true); Boolean b2 = new Boolean(true); if (b1 == b2) if (bi.equals(b2)) System. out.printin ("a"); else System. out. println ("b"); else if (bi.equals(b2)) System. out.println ("c"); else System. out.printIn("d");
A.a
B.b
C.c
D.d
第23题:
设VAR1、VAR2为字变量,LAB为标号,分析下列指令的错误之处并加以改正。 (1) ADD VAR1,VAR2 (2) MOV AL,VAR2 (3) SUB AL,VAR1 (4) JMP LAB[SI] (5) JNZ VAR1 (6) JMP NEAR LAB
第24题:
正确,尽管变量var2定义了两次,但程序自动将它们看成一个变量;
正确,前面出现的变量var2有效期仅在if中,不会与后面的变量var2重叠 ;
错误,if 块中的变量var2有效期从这里直到函数结束,因此会出现变量重叠;
错误,不管变量在哪里定义,它们都会在函数入口处初始化,因此会出现变量重叠;