
例1 阅读下列代码:
Public class Testl {
Public static void main ( String args[] ) {
Float t=9.0f ;
Int q=5;
System.out.println ( (t++)*(--q)) ;
}
}
程序运行结果为____D____ .
A) 40 B) 40.0 C)36 D) 36.0
例2 阅读下列代码:
Public class Test2{
Public static void main( String args[] ){
System.out.println(5/2);
}
}
程序运行结果为_____D_____.
例3 阅读下列代码:
Public class Test3{
Public static void main ( String args[] ) {
System.out.println(100%3);
System.out.println(100%3.0);
}
}
A)1和1 B)1和1.0 C)1.0和1 D)1.0和1.0
例4 阅读下列代码:
Public class Test4{
Public static void mian ( String args[] ) {
Int a=4,b=6,c=8;
String s=”abc”;
System.out.println( a+b+s+c );
System.out.println();
}
}
程序运行结果为____D____.
A) ababcc B) 4688 C) 46abc8 D) 10abc8
例5 阅读下列代码:
Public class Test5{
Public static void main ( String args[] ) {
String s1=new String (“hello”);
String s2=new Stirng (“hello”);
System.out.println(s1= =s2);
System.out.pirntln(s1.equals (s2 ) );
}
}
程序运行结果为____C____.
A) true,false B) true,true C) false,true D) false,false
例6 短路逻辑运算符包括___&&___和___||___.
例7 移位运算符可以起到对操作数乘2或者除2的作用,那么对操作数除2的移位运算符是___>>___.例8 在对一个复杂表达式进行运算时,要按运算符的优先顺序从高到低进行,同级的运算符则按照____从左到右的方向____.
例9 改正下划线处程序代码,使程序可以正确执行:
Public class Exercise31{
Public static void main ( String args[] ) {
Int a=0,b=100;
if ( ( a!=0)&( ( b/a= =1) ) System.out.println ( “succeed” );
}
}
[答案] if ( ( a!=0)&&(b/a= =1) ) System.out.pirntln(“succeed”);
例10 改正下划线处程序代码,使程序可以正确执行:
Public class Exercise32{
Public static void main ( String args[] ) {
Float f = 0.0 ;
f + = 1.0;
}
}
[答案] float f = 0.0 f;或者float f = 0;
