Java基础Day03测试题

需要答案的给我留言

http://www.yztcedu.com
—by 超哥

每日一考—Day03

不定项选择题。(每题答案的个数不固定)

  1. 2的5次方的最快算法是下面哪个?
    A、2 * 2 * 2 * 2 * 2
    B、2 << 5
    C、1 << 5
    D、1 >> 5

  2. 下面的代码片段执行后输出多少?
    A、3
    B、4
    C、5
    D、6

    int a = 2;
    int b = 3;
    int c = ++a >= b++ ? a++ : b++;
    System.out.println(c);
  3. java语句有哪些结构?
    A、顺序结构
    B、循环结构
    C、选择结构
    D、跳转结构

  4. 下面代码片段执行后输出什么?
    A、你真坏
    B、你真好
    C、A和B都会输出
    D、A和B都不会输出

    int a = 5;
    int b = 6;
    if(a++ < b--){
        a--;
        System.out.println("你真好");
    }else{
        b++;
        System.out.printlln("你真坏");
    }
    
  5. 在上题目中的代码执行结束后,a和b的值分别是多少?
    A、a = 6 b = 6
    B、a = 6 b = 7
    C、a = 5 b = 7
    D、a = 5 b = 5

  6. 下面代码执行结果是( )
    A、a
    B、b
    C、if中的条件必须是boolean表达式,所以编译错误
    D、ab

    public class Test{
        public static void main(String[] args){
            boolean bo1 = false;
            if(bo1 = true){
                System.out.println("a");
            }else{
                System.out.println("b");
            }
        }
    }
  7. 以下代码输出结果是( )
    A、2
    B、2 3
    C、2 3 4
    D、2 3 4 default

    public class Test{
        public static void main(String[] args){
            byte b = 2;
            switch(b){
                case 1:
                System.out.println("1");
                case 2:
                System.out.println("2");
                case 3:
                System.out.println("3");
                case 4:
                System.out.println("4");
                break;
                default:
                System.out.println("default");
            }
        }
    }
  8. switch都支持哪些数据类型?
    A、byte
    B、short
    C、long
    D、枚举
    E、double
    F、String
    G、int
    H、char

  9. 下面代码的输出几个*:
    A、3个
    B、1个
    C、无数个
    D、编译错误

    public class Test{
        public static void main(String[] args){
            for(byte b = 125; b < 128; b++){
                System.out.pritnln("*");
            }
        }
    }
    
  10. 下面代码运行结果多少*:
    A、编译错误
    B、无法确定
    C、无数个(死循环)
    D、运行错误

    public class Test{
        public static void main(String[] args){
            for(; ; ){
                System.out.pritnln("*");
            }
        }
    }
  11. 下面代码的循环体执行多少次?
    A、1次
    B、0次
    C、无限次
    D、编译错误

    public class Test{
        public static void main(String[] args){
            int a = 4;
            while(a == a++){
                System.out.println("*");
            }
        }
    }
    
  12. 下面代码的循环体执行多少次?
    A、1次
    B、0次
    C、无限次
    D、编译错误

    public class Test{
        public static void main(String[] args){
            int a = 4;
            while(a++ == a){
                System.out.println("*");
            }
        }
    }
    
  13. while循环和 do…while循环的区别是: ( )
    A.没有区别,这两个结构任何情况下效果一样
    B.while循环比 do…while循环执行效率高
    C.while循环是先循环后判断,所以循环体至少被执行一次
    D.do…while循环是先循环后判断,所以循环体至少被执行一次
  14. 下面代码的运行结果是:
    A、0 1 2 3 4 5
    B、0 1 3 4 5
    C、0 1
    D、编译错误

    public static void main (String[] args) {
        for(int i=0; i<=5; i++){
            if(i==2){
                continue;
            }
            System.out.println (i) ;
        }
    }
  15. 下面代码的运行结果是:
    A、0 1 2 3 4 5
    B、0 1 3 4 5
    C、0 1
    D、编译错误

    public static void main (String[] args) {
        for(int i=0; i<=5; i++){
            if(i==2){
                break;
            }
            System.out.println (i) ;
        }
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值