try{}catch{}finally{}运行后的执行结果
发布日期:2021-10-12 20:08:26 浏览次数:8 分类:技术文章

本文共 1089 字,大约阅读时间需要 3 分钟。

1.以下执行结果?

(1).代码

public class Demo {    public static void main(String[] args) {        System.out.println(getValue());    }    public static int getValue(){        Scanner sc = new Scanner(System.in);        System.out.println("输入一个数");        int i = sc.nextInt();        try {            System.out.println("try值:"+i);            return i++;//10        }catch(Exception e){            return i++;        }finally {            System.out.println("finally值:" + i);//11            return i++;        }    }}

(2).执行结果

输入一个数10try值:10finally值:1111

2.以下执行结果?

2.1代码

public class Demo {    public static void main(String[] args) {        System.out.println(getValue());    }    public static int getValue(){        Scanner sc = new Scanner(System.in);        System.out.println("输入一个数");        int i = sc.nextInt();        try {            System.out.println("try值:"+i);            return i++;//10        }catch(Exception e){            return i++;        }finally {            System.out.println("finally值:" + i);//11//            return i++;        }    }}

2.2执行结果

输入一个数10try值:10finally值:1110

转载地址:https://blog.csdn.net/qq_39773004/article/details/107698262 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:二叉查找树代码java+运行结果
下一篇:如果try{}里面有一个return语句,那么紧跟着这个try后的finally{}里面的代码会不会执行?

发表评论

最新留言

感谢大佬
[***.8.128.20]2024年04月11日 21时11分47秒