Skip to content

Commit 0a60776

Browse files
Add the NoZeroDiv class
1 parent 70f1c11 commit 0a60776

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.guide.c5;
2+
3+
// Prevent a division by zero using the ?.
4+
public class NoZeroDiv {
5+
public static void main(String[] args) {
6+
int result;
7+
8+
for (int i = -5; i < 6; i++) {
9+
result = i != 0 ? 100 / i : 0;
10+
if (i != 0)
11+
System.out.println("100 / " + i + " is" + result);
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)