Blueherb In solitude, where we are least alone

判断错误返回数据

/*判断j为零时和不为零时判断,返回错误类型
package
test; import java.util.Scanner; import javax.swing.JOptionPane; public class Secetion { public static void main( String args[] ) { int i=100; int j=0; int c; Scanner sc=new Scanner(System.in); System.out.println("请输入一个数字"); j=sc.nextInt(); c=i/j; try { c = i/j; // Causes division-by-zero exception throw new Exception("Hello.Exception!"); } catch ( ArithmeticException e) { System.out.println("被0除."+ e.getMessage()); } catch (Exception e) { if (e instanceof ArithmeticException) System.out.println("被0除"); else { System.out.println(e.getMessage()); } }

 

posted @ 2019-10-28 20:40  帅气的小土豆  阅读(148)  评论(0编辑  收藏  举报