Help us understand the problem. What is going on with this article?

例外処理の練習(ArithmeticException)

More than 1 year has passed since last update.
ThrowsExam.java
package JavaStudy;
import java.util.Scanner;
//整数を入力された値で割る処理
//0で割る場合は例外処理
public class ThrowsExam {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a = 6873;
        int retry = 0 ;
        System.out.println("プログラムを開始します");
        do {            

            System.out.print("数値を入力してください。");
            try{
                int b = scan.nextInt();
                double c = divide(a,b);
                System.out.println(c);
            }catch(ArithmeticException e) {
                e.printStackTrace(); //エラーの経路・内容を表示
                System.out.println("入力値は0より大きい必要があります。");

            }
            do { //リトライの数値が0、1以外の時は繰りかえし
                System.out.print("Retry? [1 = yes / 0 = no]");
                retry = scan.nextInt();
                if(retry>1)
                    System.out.println("無効な数値が入力されました。");
            }while(!(retry <= 1 && retry >= 0));

        }while(retry == 1);
        System.out.println("プログラムを終了します");
    }

    public static double divide(int a, int b) throws ArithmeticException  {
        return a / b;
    }
}
sumy
Java勉強中です。
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away