|
| 1 | +--- |
| 2 | +title: Java Program to calculate quotient and reminder |
| 3 | +shortTitle: Calculate Quotient and reminder |
| 4 | +description: In this program you'll learn, How you can calculate the quotient and reminder of a number (divident) by dividing a number (divisor) |
| 5 | +--- |
| 6 | + |
| 7 | +import {TipInfo} from '@/components/Tip' |
| 8 | + |
| 9 | +To understand this example, you should have the knowledge of the following Java programming topics: |
| 10 | + |
| 11 | +- [Java Operators](/docs/operators) |
| 12 | +- [Java Basic Input and Output](/docs/basic-input-output) |
| 13 | + |
| 14 | +## Calculating Quotient and reminder |
| 15 | + |
| 16 | +A Java program that find Quotient and Reminder is as follow: |
| 17 | + |
| 18 | +```java |
| 19 | +import java.util.Scanner; |
| 20 | +public class quotient_reminder { |
| 21 | + public static void main(String[] args){ |
| 22 | + int dividend, divisor; |
| 23 | + Scanner input = new Scanner(System.in); |
| 24 | + System.out.print("Enter the dividend: "); |
| 25 | + dividend = input.nextInt(); |
| 26 | + System.out.print("Enter the divisor: "); |
| 27 | + divisor = input.nextInt(); |
| 28 | + int quotient = dividend / divisor; |
| 29 | + int reminder = dividend % divisor; |
| 30 | + |
| 31 | + System.out.println("Quotient: " + quotient + "\nReminder: " + reminder); |
| 32 | + input.close(); |
| 33 | + } |
| 34 | +} |
| 35 | +``` |
| 36 | +### Output 1: |
| 37 | + |
| 38 | +```text |
| 39 | +Enter the dividend: 11 |
| 40 | +Enter the divisor: 15 |
| 41 | +Quotient: 0 |
| 42 | +Reminder: 11 |
| 43 | +``` |
| 44 | + |
| 45 | +### Output 2: |
| 46 | +```text |
| 47 | +Enter the dividend: 100 |
| 48 | +Enter the divisor: 8 |
| 49 | +Quotient: 12 |
| 50 | +Reminder: 4 |
| 51 | +``` |
| 52 | + |
| 53 | +To calculate the Quotient or reminder we first need two number as prerequesties among which the division operation is going to performed to calculate the Quotient or Reminder |
| 54 | + |
| 55 | +Here, we are taking two input from user for some prompt and sotring these value in variable ```dividend, and divisor```. Now in order to calculate the quotient we need to divide a number (divident) by some another number (divisor) the number which we get after performing divison is we get quotient. |
| 56 | +Thus, here we perform the divison operation using ```/``` operator and storing the value in ```quotient``` variable. |
| 57 | + |
| 58 | +And what about reminder ? many time the divison isn't the absolute. So inorder to calculate the reminder we are calculating it using modulas operator and storing it in ```reminder``` variable. |
| 59 | +After getting Quotient and Reminder we just printing these. |
| 60 | + |
| 61 | + |
| 62 | +<TipInfo> |
| 63 | + |
| 64 | +Don't know how to take input from the user ? Look at [this examples](/docs/basic-input-output#java-input) |
| 65 | + |
| 66 | +Here two input numbers are taken from user one after another with space in between them which distinguish between two different inputs, this useful behavior is because of the default settings of Scanner called as Delimiter, [learn more here](https://www.javatpoint.com/post/java-scanner-delimiter-method). |
| 67 | + |
| 68 | +</TipInfo> |
0 commit comments