Testing and Debugging
Debug Trace
A debug flag can print intermediate values while leaving the final result unchanged.
Debug Trace
DebugTrace.java
public class DebugTrace {
public static void main(String[] args) {
boolean debug = ;
int width = 6;
int height = 4;
int area = width * height;
if (debug) {
System.out.println("debug width=" + width + " height=" + height);
}
System.out.println("area=" + area);
}
}
public class DebugTrace {
public static void main(String[] args) {
boolean debug = ;
int width = 6;
int height = 4;
int area = width * height;
if (debug) {
System.out.println("debug width=" + width + " height=" + height);
}
System.out.println("area=" + area);
}
}
debug flag
A flag lets diagnostic output be turned on or off without changing the calculation.
intermediate value
Printing the intermediate values helps confirm how the result was built.