More Debugging
Add the following file to your project:Lab5Example.java
The method
longestRun
is an attempt to implement a nice algorithm for finding the length of the longest run in a string, where a "run" just means the same character appearing multiple times in a row. For example, here are a few test cases from the sample code:
public static void main(String[] args) { System.out.println(longestRun("aabbbccd")); System.out.println("Expected 3 (three b's in a row)"); System.out.println(longestRun("aaa")); System.out.println("Expected 3 (three a's in a row)"); System.out.println(longestRun("acbbbb")); System.out.println("Expected 4 (four b's in a row)"); }Your task is to finish the implementation of the algorithm by correcting the errors. Trace through the code carefully using the debugger. Debugging other people's code can be very difficult, but fortunately the code is pretty well commented and the variable names make sense, so we can see the programmer's intention. Leave the parts that work and fix it where it doesn't work.
Checkpoint 2
Show your TA the corrected versions offindLastP
, findFirstP
, and longestRun
. Demonstrate that you can
- Step through the iterations of a loop
- Break into an infinite loop
- Set an exception breakpoint