Quotient and remainder

This code performs division of two numbers and computes the quotient and remainder.

  1. The Scanner class is imported to read user input.
  2. A Scanner object is created with System.in as the source of input.
  3. The program prompts the user to enter the dividend and divisor using the nextInt() method of the Scanner class.
  4. The values entered by the user are stored in the dividend and divisor variables.
  5. The scanner object is then closed using the close() method to release any resources associated with it.
  6. The division operation is performed, and the quotient and remainder are stored in their respective variables.
  7. The results of the division, i.e. the quotient and remainder, are then displayed on the console using println() and print() methods.
import java.util.Scanner;

class QuotientReminder {
	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);

		int dividend, divisor, quotient, remainder;

		System.out.print("Please enter dividend: ");
		dividend = reader.nextInt();
		System.out.print("Please enter divisor: ");
		divisor = reader.nextInt();
		quotient = dividend / divisor;
		remainder = dividend % divisor;
		System.out.println("Quotient is: " + quotient);
		System.out.print("Remainder is: " + remainder);
Please enter dividend: 118
Please enter divisor: 12
Quotient is: 9
Remainder is: 10