1.如果执行了try块没有异常,则继续运行finally块中的语句,即使try块通过return,break,或者continue于最后的语句退出,finally中的语句也是会执行的。
总结:
不管是否出现异常,finally子句总是在块完成之前执行。
代码:
import java.util.scanner; public class dividebytwo{ public static void main(string args[]){ scanner in=new scanner(system.in); int x; system.out.println("please enter integer:"); try{ string oneline=in.nextline(); x=integer.parseint(oneline); system.out.println("half of x is"+(x/2)); } catch(numberformatexception e){ system.out.println(e); } finally{ system.out.println("hello world!"); } } }
以上所述是小编给大家介绍的java关键字finally_动力节点java学院整理,希望对大家有所帮助
如对本文有疑问, 点击进行留言回复!!
【奥鹏作业答案库网】大工20春《应用统计》在线作业1【奥鹏作业答案】
网友评论