标签:++ nbsp etag void row imp rac this pac
1.
package qq; import java.util.Scanner; public class KeCheng { public static void main(String[] args) { Scanner input = new Scanner(System.in); try { System.out.println("请输入1~3之间的数字:"); int choose = input.nextInt(); switch (choose) { case 1: System.out.println("JAVA"); break; case 2: System.out.println("C++"); break; case 3: System.out.println(".net"); break; default: System.out.println("输入错误!没有该课程"); break; } } catch (Exception e) { e.printStackTrace(); System.err.println("出现异常!"); }finally { System.out.println("感谢建议"); } } }
输出为:
2.
package qq; /** * 年龄类 */ public class Age { private int age; public int getAge() { return age; } public void setAge(int age) throws Exception{ if(age<100&&age>0) { this.age = age; }else { throw new Exception("年龄不能小于0或者大于100"); } } public void print() { System.out.println("XXX的年龄为:"+this.getAge()); } }
输出为:
先执行finally块,在执行return
System.exit(1);退出虚拟机
标签:++ nbsp etag void row imp rac this pac
原文地址:https://www.cnblogs.com/Zhangchuanfeng1/p/10406380.html