Write a Java Program to calculate quotient and remainder of 2 integers and print the results.
Click Here to View the Solution!
public static void main(String args)
, divisor =5
quotient = dividend / divisor;
remainder = dividend % divisor;
System.out.println("Quotient = "
System.out.println("Remainder = "
Click Here to View the Output!
Quotient = 7
Remainder = 2
Click Here to View the Explanation!
- In this program, two variables
divisorare declared and then
5are stored in them respectively.
- Now, to find the
- Since both variables are integers the resultant will be computed as an integer as well.
- Mathematically 37/5 is equal to 7.4, but as we used integer data type to store
int quotientvariable only stores 7 (integer part of answer).
- Likewise we used
%(Modulus) operator to find the remainder. So, the remainder of 37/5, i.e. 2 is stored in an integer in variable
remainderon console screen.