Java入门测试题,测测你基础知识掌握程度(附答案)

直接上题,如下:
1.
class Happy {
    public static void main(String args[])     {
        int i = 1 ;   
        int j = i++ ;
        if((i==(++j))&&((i++)==j))     {
            i += j ;
        }
        System.out.println("i = "+i);
    }
}
运行完上面代码之后输出i的值是多少?
A. 4
B. 5
C. 3
D. 6
2. 下面的数据声明及赋值那一个是没有错误的?
A. float f = 1.3;
B. char c = "a"
C. byte b = 257
D. int i = 10
3. 编译Java源程序文件产生的字节码文件的扩展名为?
A. java
B. class
C. html
D. exe
4. 现在假设有如下程序:
public class Demo {
    public static void main(String args[]) {
        boolean flag = 10%2 == 1 && 10 / 3 == 0 && 1 / 0 == 0 ;
        System.out.println(flag ? "aliyunedu" : "yootk") ;
    }
}
以上程序的最终执行结果是什么?
A. aliyunedu
B. yootk
C. true
D. 程序出错
5. 现在假设有如下程序:
public class Demo {
    public static void main(String args[]) {
        int x = 10 ;
        double y = 20.2 ;
        long z = 10L;
        String str = "" + x + y * z ;
        System.out.println(str) ;
    }
}
以上程序的最终执行结果是什么?
A. 10202.0
B. 0212.0
C. 302.0
D. 1020.210
6. 现在假设有如下程序:
public class Demo {
    public static void main(String args[]) {
        String str = "" ;
        for (int x = 0 ; x < 5 ; x ++) {
            str += x ;
        }
        System.out.println(str) ;
    }
}
以上程序最终的执行结果是什么?
A. 01234
B. 10
C. 14
D. 25
7. 现在假设有如下程序:
public class Demo {
    public static void main(String args[]) {
        System.out.println(inc(10) + inc(8) + inc(-10)) ;
    }
    public static int inc(int temp) {
        if (temp > 0) {
            return temp * 2 ;
        }
        return -1 ;
    }
}
以上程序的最终执行结果是什么?
A. 35
B. 8
C. 28
D. 12
8. 现在假设有如下程序:
public class Demo {
    public static void main(String args[]) {
        char c = 'A' ;
        int num = 10 ;
        switch(c) {
            case 'B' :
                num ++ ;
            case 'A' :
                num ++ ;
            case 'Y' :
                num ++ ;
                break ;
            default :
                num -- ;
        }
        System.out.println(num) ;
    }
}
以上程序的最终执行结果是什么?
A. 11
B. 13
C. 12
D. 10
9. 现在假设有如下程序:
public class Demo {
    public static void main(String args[]) {
        int sum = 0 ;
        for (int x = 1 ; x < 10 ; x ++) {
            sum += x ;
            if (x % 3 == 0) {
                continue ;
            }
        }
        System.out.println(sum) ;
    }
}
以上程序的最终执行结果是什么?
A. 6
B. 0
C. 程序错误,死循环
D. 45
10. 现在假设有如下程序:
public class Demo {
    public static void main(String args[]) {
        int sum = 0 ;
        for (int x = 0 ; x < 10 ; x ++) {
            sum += x ;
            if (x % 3 == 0) {
                break ;
            }
        }
        System.out.println(sum) ;
    }
}
以上程序的最终执行结果是什么?
A. 6
B. 0
C. 程序错误,死循环
D. 45
答案:BDBBA AACDB
你做对了多少呢?若想学习请到 http://click.aliyun.com/m/23565/

本文转载自:阿里云云栖社区更多技术干货及好文,请关注
官方微博:@阿里云云栖社区   现在有免费赠手机的活动哦
官方微信:云栖社区(yunqiinsight)
官方知乎号:阿里云云栖社区
  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值