Page 93 - CA_Blue( J )_Class9
P. 93
For example,
If int m=10, n=5 then, m/n = 10/5 = 2
Then, n/m = 5/10 = 0
If double i=-20, j= 6 then, i/j = -20 / 6 = -3.3333333333333335
If double i= -20.5, j = -10 then, i/j = -20.5 / -10 = 2.05
Program 8 Example of division (/) operator
1 class division_operator
2 {
3 public static void main(int a, int b)
4 {
5 double c=(double)a/b;
6 System.out.println("Result of Division : " + c);
7 }
8 }
Input: You will get the following output:
Remainder or Modulus (%) Operator
The remainder or modulus (%) operator is used for finding the remainder between two values or operands either
of the integer literals or real literals. The result of the modulus operator may be positive or negative depending on
the values. For example:
if i=-20 , j= 6 then, i%j = -20 % 6 = -2
if i= -20.5 , j = -10 then, i%j = -20.5 % -10 = -0.5
Program 9 Example of Remainder or Modulus (%) operator.
1 class modulus_operator
2 {
3 public static void main(int a, int b)
4 {
5 int c=a%b;
Operators in Java 91

