判断错误返回数据

/*判断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()); } }
原文地址:https://www.cnblogs.com/sunhongbin/p/11755384.html