計(jì)算機(jī)等級(jí)考試二級(jí)Java備考練習(xí)(4)

字號(hào):

9 改正下劃線處程序代碼,使程序可以正確執(zhí)行:
    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 改正下劃線處程序代碼,使程序可以正確執(zhí)行:
    Public class Exercise32{
    Public static void main ( String args[] ) {
    Float f = 0.0 ;
    f + = 1.0;
    }
    }
    [答案] float f = 0.0 f;或者 float f = 0;
    第4章 流程控制
    1 閱讀下面代碼段:
    Public class Test
    {
    Public static void main (string args [ ])
    {
    Int m ;
    Switch (m)
    {
    Case 0 : System.out.println(“case 0”); break;
    Case 1:
    Case 2:
    Case 3: system.out.println(“Non Zero”);
    }
    }
    }
    將不輸出 “Non Zero”的m值是 A
    A) 0 B)1 C)2 D) 3
    2 閱讀下列代碼段:
    Int i= 3, j ;
    Outer:while(i>0)
    {
    j = 3 ;
    inner: while (j>0)
    {
    if (j<2) break outer ;
    System.out.println (j +”and” + i ) ;
    j -- ;
    }
    i -- ;
    }