java程序设计基础题期末考试

四、 简答题 (共6题,30分)

1、写出下列程序的运行结果____01234_____

 public class X3_3_1 {    

public static void main(String[] args) {

for(int i=0; i<10; i++){

      if(i==5) break;

       System.out.print(i);

      }

   }

}

扫描二维码关注公众号,回复: 14346191 查看本文章

(5.0)

正确答案:01234 

2、写出下列程序的运行结果__________。

public class X3_1 {

public static void main(String args[]){

System.out.println("This is my first Java Application!");

    }

}

(5.0)

正确答案:This is my first Java Application!

3、public class X3_3_8 {    

public static void main(String[] args) {

    char ch='7';

    int r=10;

    switch(ch+1){

     case '7': r += 7;

     case '8': r += 8;

     case '9': r += 9;

     default:

    }

    System.out.print(r);

}

}

 

4、public class fff

{

void printValue(int m)

{

do { System.out.println("The value is"+m);}

while( --m > 10 )

}

public static void main(String arg[])

{

int i=10;

Test t= new Test();

t.printValue(i);

}

}

(5.0)

正确答案: The value is10

5、写出下列代码执行后的输出结果_______。

int a=19,b=8;

int x=(a%b>5)? a+b:a-b;

System.out.println(x);

(5.0)

正确答案: 11

6、请在下方插入处插入合适的代码:________________

public class T{

int r;

int s;

T(int x,int y){

r=x;

s=y;

}

}

class S extends T{ int t;

public S(int x,int y,int z){ //插入代码处:要求插入代码实现 r=x,s=y

t=z;

}

}

(5.0)

正确答案: super(x,y);

猜你喜欢

转载自blog.csdn.net/qq_39154376/article/details/125454081