桂林理工大学第十届Java程序设计初试竞赛试题+答案

一、单项选择题(每小题4分,共40分)

1、以下程序的运行结果为( D )

class Tester{

public static void main(String[] args){

       int x = 12, y = 13;

      System.out.println(x + " + " + y + " = " + x + y); 

}  

}

A. x + y = 25              B. 12 + 13 = 25               C. x + y = 1213             D. 12 + 13 = 1213

2、以下程序的运行结果为( B )

public class TestClass{

  public static void main(String[] args){

      int a = 1;

      switch (a) {

         case 1: a += 1;

         case 2: a +=2; break;

         case 3: a += 3;

         default: a = 0;     

}

      System.out.println(a); 

}

A. 2                       B. 4                         C. 7                      D. 0

 

(4分)3、以下程序的运行结果为:             B                                          

public class Tester{

public static void main(String args[]) {        

int count = 1 ;

int[] value=  new int[2]; 

value[0] = 1;

        testMethod(count, value);

       System.out.println(count + "; " + value[0]);  

}

public static void testMethod(int count, int[] value) {  

count = count + 2;

value[0] = value[0] + 2;  

}

}

A. 1; 1                     B. 1; 3                      C. 3; 1                     D. 3; 3

 

4、以下程序的运行结果为( C )

public class Tester{                                    

    public static int add(int x){                  

        if (x > 0)    

            return x + add(x - 2);

        return x;   

}   

    public static void main(String[] args){

        System.out.println(add(5));  

}

}

A. 0                        B. 1                       C. 8                        D. 以上都不对

5、设类Car是类Vehicle的派生类,car, vehicle分别是类Car与Vehicle的对象,以下语句存在语法错误的是(A )

A. car = new Vehicle();         B. vehicle = new Car();       C. car = (Car) vehicle;          D. vehicle = car;

 

6、以下关于Java继承与接口的描述中,正确的是( B )

A. 支持多继承与多接口实现               B. 支持单一继承与多接口实现

C. 支持单一继承与单一接口实现                         D. 支持多继承与单一接口实现

 

7、设value为一个四位整数(如1234),以下代码能够获得其百位上数值(应为2)的是(A )

A. value / 100 % 10;          B. value % 100 / 10;          C. value / 10 % 100;            C. value % 10 / 100;

 

8、以下能够为value随机赋予[10, 100)之间的整数值的是(A)

A. value = (int) (Math.random() * 90) + 10;                  B. value = (int) (Math.random() * 100) - 10;

A. value = (int) (Math.random() * 10) + 90;                  D. 以上都不对

 

9、以下表达式可以用于判断某年(用year表示)是否是润年(表达式值为true表示是润年,否则不是润年)的是(B )

A. (year % 4 == 0) && ((year % 100 != 0) || year % 400 == 0)  

B. (year % 4 == 0) && (year % 100 != 0) || year % 400 == 0

C. (year / 4 == 0) && ((year / 100 != 0) || year / 400 == 0)       

D. (year / 4 == 0) && (year / 100 != 0) || year / 400 == 0

 

10、以下程序的运行结果为( D )

class Tester{

    static int a = 1;

    public static void main()    {       

        for (int i = 0;i < 3; i ++) fun();

        System.ou

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qq_158032149

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值