int count = 0; int total = 345; if ( count > 0 ) { if ( total / count > 80 ) System.out.println("Acceptable Average"); else System.out.println("Low Average"); } else System.out.println("No values to average.");
The first if statement.
acts as a "guard" that prevents division by zero.
When count is zero,
it prevents the true-branch from executing.
It is easy to get caught up in complicated boolean expressions and to use them when a nested-if is more appropriate. The answer to the question is probably better than the original code fragment because it is easier to understand and writes better messages to the monitor.
What is the true/false value of:
12 > 6 || 18 > 1