Using the Division Algorithm Create a Java method that does the following: 1) Ask the user for a dividend and a divisor both of "int" type. 2) Computes the quotient of the division. The quotient (answer) must be of the "int" type. Do NOT use the method " / " provided in Java in your code. Remember that it gives wrong answers when some of the inputs are negative.
import java.util.Scanner; public class DivisionAlgorithm { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n1, n2; System.out.print("Enter first integer input: "); n1 = scanner.nextInt(); System.out.print("Enter second integer input: "); n2 = scanner.nextInt(); while(n1>=n2){ n1 = n1 - n2; } System.out.println("Quotient = "+n1); } }
Get Answers For Free
Most questions answered within 1 hours.