Java Program to find the quotient and reminder of an integer number

Here we are explaining how to write a java program to find out the quotient and remainder of an integer number. So first we have to read the number which is to be divided from the user. Also, we have to read the dividend from the user. Then just divide the number by using the / operator so we will get the quotient. To get the remainder we can use the % operator.

How to read an integer number in java?

For reading an integer number from the user in java, we can use nextInt() function in the java Scanner class. In this program, we have to read two integer numbers. So we have to write the code as follows:

    System.out.print("Enter the number which is to be divided:");
      int number = sc.nextInt()

Here we read the number which is to be divided into the variable number by using sc which is the object of the java Scanner class. Similarly, we will read the dividend also. Which is shown below.
          System.out.print("Enter the dividend:");
          int dividend = sc.nextInt();

How to implement the java program to find out the quotient and remainder of a number?

First, we have to declare the class Divide. Then open the main function. Then read the number which is to divide into the integer variable number. Read the divided into the variable dividend. Then find out the quotient as quotient = number/dividend and remainder as remainder = number % dividend. Then display the remainder and quotient.

 

ALGORITHM

STEP 1: Declare the class Division with a public modifier.

STEP 2: Open the main() to start the program, Java program execution starts with the main()

STEP 3: Read the number which is to be divided is from the user into the variable number.

STEP 4: Read the dividend from the user into the variable dividend.

STEP 5: Calculate the quotient as quotient=number/dividend.

STEP 6: Calculate the remainder as remainder=number % dividend.

STEP 7: Then display the Quotient and remainder.

Java Source Code

                                          import java.util.Scanner;   
public class Division {
    public static void main(String[] args) {
          Scanner sc = new Scanner(System.in);//Create the object of Scanner class.
        System.out.print("Enter the number which is to be divided:");
       int number = sc.nextInt();//Read the number from the console
          System.out.print("Enter the dividend:");
       int dividend = sc.nextInt();//Read the number from the console
        int quotient = number / dividend;
        int remainder = number % dividend;
        System.out.println("Quotient =" + quotient);
        System.out.println("Remainder =" + remainder);
    }
}
                                      

OUTPUT

OUTPUT 1

Enter the number which is to be divided:
10
Enter the dividend:
2
Quotient =5
Reminder=0

OUTPUT 2
Enter the number which is to be divided:
20
Enter the dividend:
2
Quotient =10
Reminder=0