Debugging Practice
From CompSciWiki
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! |