Computer Science, asked by unzilakhan47, 1 year ago

Write a program in Java to print the real quotient obtained by dividing two integer number.Also print the remainder obtained after dividing them

Answers

Answered by nikhil8496
1
In this program, you'll learn to compute quotient and remainder from the given dividend and divisor in Java.


Example: Compute Quotient and Remainder
public class QuotientRemainder {

public static void main(String[] args) {

int dividend = 25, divisor = 4;

int quotient = dividend / divisor;
int remainder = dividend % divisor;

System.out.println("Quotient = " + quotient);
System.out.println("Remainder = " + remainder);
}
}
When you run the program, the output will be:

Quotient = 6
Remainder = 1
In the above program, two numbers 25 (dividend) and 4 (divisor) are stored in two variables dividend and divisor respectively.

Now, to find the quotient we divide dividend by divisor using / operator. Since, both dividend and divisor are integers, the result will also be computed as an integer.

So, mathematically 25/4 results 6.25, but since both operands are int, quotient variable only stores 6 (integer part).

Likewise, to find the remainder we use the % operator. So, the remainder of 25/4, i.e. 1 is stored in an integer variable remainder.

Finally, quotient and remainder are printed on the screen using println() function.

unzilakhan47: i am not a boy
nikhil8496: ok sister
unzilakhan47: follow me
unzilakhan47: please
nikhil8496: ok
nikhil8496: follow me please
unzilakhan47: i have already
nikhil8496: thank you
nikhil8496: zila khan
nikhil8496: it is right
Answered by stylishtamilachee
7

Answer:

public class Calc

{

void compute( )

{

int a = 17, b = 3;

int quotient, remainder;

quotient = a / b ;

remainder = a % b ;

System.out.println( "For 17 / 3") ;

System.out.println( "Quotient = " + quotient) ;

System.out.println( "Remainder = " + remainder) ;

}

}

Output:

For 17 / 3

Quotient = 5

Remainder = 2

Java:

Java is very rich in built-in operators. In fact, Java places more significance on operators than most other computer languages do. Java offers different classes of operators : arithmetic, relational, logical, increment-decrement, conditional, bitwise etc.

Similar questions