Difference between revisions of "Debugging Practice"
From CompSciWiki
Line 2: | Line 2: | ||
|ProblemName=Debugging Practice | |ProblemName=Debugging Practice | ||
− | |Problem=Find the bugs in the code provided below. Hint: there are | + | |Problem=Find the bugs in the code provided below. Hint: there are lots |
<pre> | <pre> | ||
int lastSpace = 0; | int lastSpace = 0; |
Revision as of 01:10, 6 April 2010
Back to the Program-A-Day homepage
ProblemFind the bugs in the code provided below. Hint: there are lots int lastSpace = 0; int nextSpace = 0; String result = ""; String reversedWord = ""; String currWord = ""; for( int i = 0; i < str.len; i++ ) { nextSpace = str.indexOf( ' ', lastSpace ); currWord = str.substring( lastSpace, nextSpace ); for( int j = 0; j < currWord.len; j++ ) { reversedWord = reversedWord + currWord.charAt( j ); } result = result + reversed; } |
SideSectionTitle
An image or By Students section | |
---|---|---|
SolutionThe solution... | ||
CodeSolutionCode goes here. Please DO NOT put your code in <pre> tags! |