In this post, we are going to write a simple Java Program to find the Quotient & Remainder. Before writing the program, let’s see what is a Remainder and a Quotient in mathematics?.
Here is an example:
45 รท 7 = 6 and 3
Dividend Divisor Quotient Remainder
In the above example, 45 is the Dividend, 7 is the Divisor, 6 is the Quotient and 3 is the Remainder.
So the remainder is the “
So in Java Program we can achieve this by using the / and % operators, see the below expressions
quo = dividend / divisor -> will give the quotient
rem = dividend % divisor -> will give the remainder
Let’s write the Java Program now:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
import java.util.Scanner; /** * * @author agur */ public class QuoRem { public static void main(String[] args){ int dividend, divisor, quo, rem; Scanner in = new Scanner(System.in); //get the dividend value System.out.print("Enter Dividend:"); dividend = in.nextInt(); //get the divisor value System.out.print("Enter Divisor:"); divisor = in.nextInt(); //find quotient quo = dividend / divisor; //find reminder rem = dividend % divisor; //print the result System.out.println("Quotient: "+quo); System.out.println("Remainder: "+rem); } } |
Output of the above program:
1 2 3 4 |
Enter Dividend:45 Enter Divisor:7 Quotient: 6 Reminder: 3 |