import java.util.Scanner;
public class QuotientRemainder {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the dividend: ");
int dividend = scanner.nextInt();
System.out.print("Enter the divisor: ");
int divisor = scanner.nextInt();
int quotient = dividend / divisor;
int remainder = dividend % divisor;
System.out.println("The quotient of " + dividend + " divided by " + divisor + " is " + quotient);
System.out.println("The remainder of " + dividend + " divided by " + divisor + " is " + remainder);
}
}
Enter the dividend: 24
Enter the divisor: 5
The quotient of 24 divided by 5 is 4
The remainder of 24 divided by 5 is 4
Scanner
class to read two numbers input by the user. We then use the division and modulo operators (/
and %
) to compute the quotient
and remainder of the two numbers. quotient
in a variable called quotient
and the remainder in a variable called remainder
. Finally, we print out a message displaying the values of the dividend, divisor, quotient, and remainder.