In this article, we will write a Java program to calculate the Quotient and Remainder when one number is divided by another.
Example: Program to find Quotient and Remainder
In the following program, we have two integer numbers, num1, and num2, and we are calculating the quotient and remainder when num1 is divided by num2, so num1 is the dividend and num2 is the divisor.
public class JavaExample { public static void main(String[] args) { int num1 = 15, num2 = 2; int quotient = num1 / num2; int remainder = num1 % num2; System.out.println("Quotient is: " + quotient); System.out.println("Remainder is: " + remainder); } }
Output:
- Quotient is: 7
- Remainder is: 1
- To calculate the quotient and remainder, we created two variables called quotient and remainder, respectively.
- To find the quotient, divide num1 by num2 with the / operator. Because both variables num1 and num2 are integers, the result will be an integer even though the mathematical result of 15/2 is 7.5. As a result, the variable quotient’s value after the operation is 7.
- We use the percent operator to find the remainder. After the operation, the variable remainder is assigned the remainder of 15/2, i.e. 1.
- The values of the variables quotient and remainder are printed at the end of the program.
Annotations in Java are used to provide metadata for your Java code. Because they are metadata, Java annotations do not directly affect the execution of your code, though some types of annotations can. Java annotations were introduced in Java 5 and are still in use today. Annotations in Java are used to provide metadata for your Java code. Because they are metadata, Java annotations do not directly affect the execution of your code, though some types of annotations can. Java annotations were introduced in Java 5 and are still in use today. Annotations in Java are used to provide metadata for your Java code. Because they are metadata, Java annotations do not directly affect the execution of your code, though some types of annotations can. Java annotations were introduced in Java 5 and are still in use today. Annotations in Java are used to provide metadata for your Java code. Because they are metadata, Java annotations do not directly affect the execution of your code, though some types of annotations can. Java annotations were introduced in Java 5 and are still in use today. Annotations in Java are used to provide metadata for your Java code. Because they are metadata, Java annotations do not directly affect the execution of your code, though some types of annotations can. Java annotations were introduced in Java 5 and are still in use today. Annotations in Java are used to provide metadata for your Java code. Because they are metadata, Java annotations do not directly affect the execution of your code, though some types of annotations can. Java annotations were introduced in Java 5 and are still in use today. Annotations in Java are used to provide metadata for your Java code. Because they are metadata, Java annotations do not directly affect the execution of your code, though some types of annotations can. Java annotations were introduced in Java 5 and are still in use today. Annotations in Java are used to provide metadata for your Java code. Because they are metadata, Java annotations do not directly affect the execution of your code, though some types of annotations can. Java annotations were introduced in Java 5 and are still in use today. Annotations in Java are used to provide metadata for your Java code. Because they are metadata, Java annotations do not directly affect the execution of your code, though some types of annotations can. Java annotations were introduced in Java 5 and are still in use today. Annotations in Java are used to provide metadata for your Java code. Because they are metadata, Java annotations do not directly affect the execution of your code, though some types of annotations can. Java annotations were introduced in Java 5 and are still in use today.