Source code of this problem statement :
// Find the quotient and reminder of a number
package asicQuestion;
import java.util.Scanner;
public class quotientAndReminder {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter dividend value");
int dividend = sc.nextInt();
System.out.println("Enter divisor value");
int divisor = sc.nextInt();
float quotient;
int reminder;
quotient = dividend / divisor;
reminder = dividend % divisor;
System.out.println("The value of quotient is: " + quotient);
System.out.println("The value of reminder is: " + reminder);
}
}
Source code for " find quotient and remainder in java" with exception handling :
// Find the quotient and reminder of a number
package asicQuestion;
import java.util.Scanner;
public class quotientAndReminder {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter dividend value");
int dividend = sc.nextInt();
System.out.println("Enter divisor value");
int divisor = sc.nextInt();
float quotient;
int reminder;
try {
quotient = dividend / divisor;
reminder = dividend % divisor;
System.out.println("The value of quotient is: " + quotient);
System.out.println("The value of reminder is: " + reminder);
} catch (Exception e) {
System.out.println("The error is: " + e);
}
}
}
Output:
public class quotientByMethod {
public static void main(String[] args) {
findValue fv = new findValue();
int quotient = fv.getQuotient(30, 5);
int reminder = fv.getReminder(30, 5);
System.out.println("The quotient is: " + quotient);
System.out.println("The reminder is: " + reminder);
}
}
class findValue {
int getQuotient(int dividend, int divisor) {
return dividend / divisor;
}
int getReminder(int dividend, int divisor) {
return dividend % divisor;
}
}
Logic for this problem i.e how to find quotient and remainder in java
What is quotient and remainder :-
- we all know, to perform a division we must need dividend and divisor. And by doing division we can get quotient and remainder.
- First we have to clear about dividend and divisor, the number which we want to divide is known as dividend. And by which number we are going to divide, is called divisor.
- Ex : let's see we want to divide 15 by 5, here dividend = 15 and divisor = 5.
- And what ever the results we are going to get when we divide 15 with 5 will be quotient and after complete division, if something not divisible that remaining number will be the remainder.
Here quotient = 3, and remainder = 0. Here remainder is 0, because 15 is completely divisible by 5.
- If we divide 15 with 6, then here ..
- Dividend = 15
- Divisor = 6,
- Quotient will be 2 and remainder will be 3.
How to implement logic in java:
๐ In java programming we division operator( / ) which return the quotient of a number. And modulus operator( % ) which gives the remainder.
Ex :- int quotient = 15 / 6 ;
int remainder = 15 % 6 ;
In this process we can find the remainder and quotient of any number by using java programming language.
Here I have used my mobile to code the problem statement.