CS 101 Notes 9/23/2010 Exam discussion: Trace Code Questions: A simple one: That is the result of y = 5 + 2 * 3; A harder one: What is the value of y in the println statement a in this code? int x = 0; int y = 0; while (x < 4) { y = y + 2; x = x + 1; } System.out.println (y); x: 0, 1, 2, 3, 4 y: 0, 2, 4, 6, 8 Debugging: What to do when the code doesn't work We need to answer the question: "What is really going on?" ONe method to do this: Debugging Print Statement int loopCounter = 1; while ( loopCounter < 10 ) { System.out.println ("Debug 1: " + loopCounter); // do something loopCounter ++ ; } Two types of errors: 1. Syntax Errors - Easier to fix (automatically detected) 2. Logic Errors - Harded to fix because they are harder to detect