标签:scanner 异常 tst generated system 面积 一个 code shu
package ert; import java.util.Scanner; public class ExceptionTest { public static void main (String []args) { int q,w,e; System.out.println("请输入除数"); Scanner chushu = new Scanner(System.in); int w1=chushu.nextInt(); System.out.println("请输入被除数"); Scanner beichushu= new Scanner(System.in); int e1=beichushu.nextInt(); try { q=w1/e1; System.out.println("结果为"+q); }catch(ArithmeticException e2){ getMessage(); System.out.println(e2.getMessage()); } finally { System.out.println("本次运算结束"); } } private static void getMessage() { // TODO Auto-generated method stub System.out.println("被除数不能为零!"); }; }
package ert; import java.util.*; public class Exception2 { public final static float PI= 3.14f; public static void main(String[] args) { try { float area; System.out.println("请输入圆的半径:"); Scanner q=new Scanner(System.in); float q1=q.nextFloat(); area=q1*q1*PI; System.out.println("圆的面积是:"+area); }catch(NumberFormatException e) { e.printStackTrace(); } } }
标签:scanner 异常 tst generated system 面积 一个 code shu
原文地址:https://www.cnblogs.com/za-ys/p/11005864.html