package com.growingwiththeweb.algorithms.interviewquestions.dividewithoutdivide;

public class Program {
    public static void main(String[] args) {
        assert divide(10,4) == 2;
        assert divide(11,4) == 2;
        assert divide(12,4) == 3;
        assert divide(13,4) == 3;
        assert divide(130,3) == 43;

        System.out.println("Tests passed");
    }

    public static double divide(double a, double b) {
        int sign = 1;
        if (a < 0) {
            a = -a;
            sign = -sign;
        }
        if (b < 0) {
            b = -b;
            sign = -sign;
        }
        double result = 0;
        while (a >= 0) {
            a -= b;
            result++;
        }
        return (result - 1) * sign;
    }
}

@@ -75,16 +75,55 @@
 ivide;%0A%0A
+import java.lang.ArithmeticException;%0A%0A
 public c
@@ -207,16 +207,17 @@
 vide(10,
+ 
 4) == 2;
@@ -242,16 +242,17 @@
 vide(11,
+ 
 4) == 2;
@@ -277,16 +277,17 @@
 vide(12,
+ 
 4) == 3;
@@ -312,16 +312,17 @@
 vide(13,
+ 
 4) == 3;
@@ -349,16 +349,17 @@
 de(130,3
+ 
 ) == 43;
@@ -372,104 +372,419 @@
     
-System.out.println(%22Tests passed%22);%0A    %7D%0A%0A    public static double divide(double a, double b) %7B
+boolean threw = false;%0A        try %7B%0A            divide(1, 0);%0A        %7D catch (ArithmeticException ex) %7B%0A            threw = true;%0A        %7D%0A        assert threw;%0A%0A        System.out.println(%22Tests passed%22);%0A    %7D%0A%0A    public static double divide(double a, double b) %7B%0A        if (b == 0) %7B%0A            throw new ArithmeticException(%0A                    %22Division by 0 is undefined: %22 + a + %22/%22 + b);%0A        %7D
 %0A   

Add exception for division by zero