hi i’m doing a java activity that will divide the two given numbers without using the “/” operator. I want to use a loop statement.
System.out.print("Enter Divident: ");
int ans1 = Integer.parseInt(in.readLine());
System.out.print("Enter Divisor: ");
int ans2 = Integer.parseInt(in.readLine());
The output is:
Enter Dividend: 25
Enter Divisor 5
5
How can solve this without using this “ans1/ans2”
if you really want to use loop to divide two numbers, you can write it like code below
after loop
cequals quotient andans1equals reminder of divisionif
abs1andabs2are signed numbers, below code should be work for division