
70 CHAPTER 2 Programming Building Blocks—Java Basics
1 /* DivisionByZero Class
2 Anderson, Franceschi
3 */
4
5 public class DivisionByZero
6 {
7 public static void main( String [ ] args )
8 {
9 double result1 = 4.3 / 0.0;
10 System.out.println( “The value of result1 is “ + result1 );
11
12 double result2 = 0.0 / 0.0;
13 System.out.println( “The value of result2 is “ + result2 );
14
15 int result3 = 4 / 0;
16 System.out.println( “The value of result3 is “ + result3 );
17 }
18 }
EXAMPLE 2.9 Results of Division by Zero
2.4.5 Division by Zero
As you might expect, Java does not allow integer division by 0. If you
include this statement in your program:
int result = 4 / ...