前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >java练习本(2019-07-10)

java练习本(2019-07-10)

作者头像
微笑的小小刀
发布2019-07-15 16:56:50
2160
发布2019-07-15 16:56:50
举报
文章被收录于专栏:java技术大本营java技术大本营

昨日翻译

昨日翻译

“Where there is love there is life. ”

——Mahatma Gandhi

“有爱就有生命。”

——圣雄甘地

今日名言

“ Love is our true destiny. We do not find the meaning Of life by ourselves alone- We find it with another. ”

—— Thomas Merton

2019.07.10问题及解析
题目
代码语言:javascript
复制
public class Test {
   public static void main(String[] args) {
       System.out.println(num());
  }

   public static int num(){
       int num = 3;
       try{
           num = num / 0;
      }catch (Exception e){
           num = 4;
      }finally {
           num = 5;
      }
       return num;
  }
}

请问上述程序的输出结果是什么?、

A.编译错误

B.3

C.4

D.5

答案与解析

1.相关知识

异常的执行顺序为try捕获到异常则执行catch语句,未捕获到则不执行catch语句,但无论如何都会执行fianlly语句。

2.答案解析

num/0,分母不能为0,因此抛出异常

被捕获后,num赋值为4

执行finally,num赋值为5

返回5,输出5

答案选D。

2019.07.11问题

题目分类

List——ArrayList、LinkedList

题目
代码语言:javascript
复制
public class Test {
   public static void main(String[] args) {
       int num = 1;
       List arrayList = new ArrayList();
       List linkedList = new LinkedList();

       long t1 = System.currentTimeMillis();
       for(int i = 0; i < 5000; i++){
           arrayList.add(0,num);
      }

       long t2 = System.currentTimeMillis() - t1;

       t1 = System.currentTimeMillis();
       for(int i = 0; i < 5000; i++){
           linkedList.add(0,num);
      }
       long t3 = System.currentTimeMillis() - t1;

       System.out.print(t2 > t3);
  }
}

请问上述代码的输出结果为:

A.true

B.false

C.编译错误

D.运行异常

END

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-07-11,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 java技术大本营 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 今日名言
  • 2019.07.10问题及解析
  • 答案与解析
    • 1.相关知识
      • 2.答案解析
        • 题目
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档