package start7_1.divideByZero; import java.text.DecimalFormat; import java.util.Scanner; /** * Example of divide-by-zero trouble * inspired by Dean & Dean 2nd ed. * p. 705-6 * Ex. 15.4 */ public class DivisionByZeroExample { public static void main(String[] args) { double numer = 0; int denom = 0; DecimalFormat format = new DecimalFormat("#.##"); Scanner in = new Scanner(System.in); System.out.println("Enter the numerator (may be a double): "); numer = in.nextDouble(); System.out.println("Enter the denominator (as an integer): "); denom = in.nextInt(); System.out.println("Result: "+numer+"/"+denom+" = "+format.format(numer/denom)); } }