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
    评论
JAVA入门代码测试是指对JAVA程序中的基本组成单元(方法、类)进行测试的过程。单元测试的目的是确保程序的小部分功能正常运行,以提高整体代码质量和可靠性。单元测试可以帮助开发人员及时发现和修复代码中的问题,并确保代码的可维护性和可扩展性。 在进行JAVA入门代码测试之前,首先需要配置好JAVA环境并安装好相应的开发工具,比如eclipse。使用eclipse可以方便地编写和运行JAVA代码。 下面是一个JAVA入门代码测试的示例: ```java public class Calculator { public int add(int a, int b) { return a + b; } public int subtract(int a, int b) { return a - b; } public int multiply(int a, int b) { return a * b; } public int divide(int a, int b) { if (b == 0) { throw new IllegalArgumentException("除数不能为零"); } return a / b; } } public class CalculatorTest { public static void main(String[] args) { Calculator calculator = new Calculator(); // 测试加法 int result1 = calculator.add(2, 3); System.out.println("2 + 3 = " + result1); // 测试减法 int result2 = calculator.subtract(5, 3); System.out.println("5 - 3 = " + result2); // 测试乘法 int result3 = calculator.multiply(4, 2); System.out.println("4 * 2 = " + result3); // 测试除法 int result4 = calculator.divide(9, 3); System.out.println("9 / 3 = " + result4); } } ``` 以上示例中,我们创建了一个Calculator类,包含加法、减法、乘法和除法等基本运算方法。然后,我们创建了一个CalculatorTest类,用于进行单元测试。在单元测试中,我们针对Calculator类的每个方法进行测试,并打印出结果。 通过运行上述代码,我们可以验证Calculator类的加法、减法、乘法和除法方法是否正常工作。如果测试通过,即表示JAVA入门代码测试成功。 参考资料: 单元测试的定义和特点 使用eclipse进行JAVA入门代码测试的步骤 JAVA代码中的注释示例<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Java单元测试入门](https://download.csdn.net/download/weixin_38735899/14940691)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [几个简单的入门JAVA代码](https://blog.csdn.net/weixin_42108054/article/details/114026351)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值