Divide using a loop
In this step, divide an integer with different divisors using a loop.
public class DivideUnsignedDemo {
public static void main(String[] args){
int dividend = 100;
for (int i = -5; i <= 5; i++) {
if (i != 0) {
int quotient = Integer.divideUnsigned(dividend, i);
System.out.println("The quotient of " + dividend + " and " + i + " is " + quotient);
}
else{
System.out.println("Cannot divide by zero");
}
}
}
}
Output:
The quotient of 100 and -5 is 0
The quotient of 100 and -4 is 0
The quotient of 100 and -3 is 0
The quotient of 100 and -2 is 0
The quotient of 100 and -1 is 0
Cannot divide by zero
The quotient of 100 and 1 is 100
The quotient of 100 and 2 is 50
The quotient of 100 and 3 is 33
The quotient of 100 and 4 is 25
The quotient of 100 and 5 is 20