import java.util.*; public class DivisionExceptionExampleWithLoop { static Scanner console = new Scanner(System.in); public static void main(String[] args) { int numerator, denominator; double quotient; boolean continueLoop = true; do { try { System.out.print("Enter the numerator: "); numerator = console.nextInt(); System.out.print("Enter the denominator: "); denominator = console.nextInt(); quotient = 1.0*numerator/denominator; System.out.println(numerator + "/" + denominator + "=\t" + quotient); continueLoop = false; //if we get to this point, we do NOT want to repeat the do-while loop } catch (ArithmeticException aeRef) { System.out.println("Zero can not be the denominator!"); console.nextLine(); //NECESSARY to get rid of the last 'bad' input from the user } catch (InputMismatchException imeRef) { System.out.println("Please enter only integers."); console.nextLine(); } } while ( continueLoop == true ); } //end main } //end class