File tree Expand file tree Collapse file tree 2 files changed +47
-1
lines changed
Expand file tree Collapse file tree 2 files changed +47
-1
lines changed Original file line number Diff line number Diff line change 1+ Operators in java
2+
3+ 2. Arithmatic Operators
4+ -> +, -, *, /, %.
5+
6+ -> For All Arithmatic operation the result is MAX(int, type of a, type of b).
7+
8+ byte b1 = 10;
9+ byte b2 = 20;
10+ byte b = b1 + b2; // compile time error.
11+ byte b = (byte) b1 + b2; // b = 30
12+
13+
14+ Case 1.
15+
16+ System.out.println(10/0);
17+ -> 10/0 is int/int so the result is int type.
18+ -> In integer type there is no way to represent Infinity that's why we get RuntimeException.
19+ -> for above case the output we get is java.lang.ArithmeticException: / by zero
20+
21+ Case 2.
22+
23+ System.out.println(10.0/0);
24+ -> 10.0/0 is double/int so the result is double type.
25+ -> In floting point type there is way to represent Infinity that's why we get Infinity.
26+ -> for above case the output we get is Infinity.
27+
28+ Case 3.
29+
30+ System.out.println(0/0);
31+ -> 0/0 is int/int so the result is int type.
32+ -> In integer type there is no way to represent undefined that's why we get RuntimeException.
33+ -> for above case the output we get is java.lang.ArithmeticException: / by zero
34+
35+ Case 4.
36+
37+ System.out.println(0/0.0);
38+ -> 0/0.0 is int/double so the result is double type.
39+ -> In floting point type there is way to represent undefined that's why we get NaN.
40+ -> for above case the output we get is NaN.
41+
42+
43+ ** Regarding Arithmatic Exception**
44+ -> Arithmetic Exception cause by only / and %.
45+ ->
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ public static void main(String[] args) {
1818 // b = b + 1; //error: incompatible types: possible lossy conversion from int.
1919 // System.out.println(b);
2020
21-
21+ System .out .println (0 /0.0 );
22+
2223 }
2324}
You can’t perform that action at this time.
0 commit comments