This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
Justin van Wilgen wrote:Hi, you are missing a bracket on line 19, change it as follows:
Better make that (int)(Math.random() * 10). Your code first converts the result of Math.random() to an int. Since Math.random() always returns a double >= 0 and < 1, the cast will always result in 0. The total will therefore also be 0.
By multiplying first, then casting, you're casting something that's >= 0 and < 10 to an int. That can be any int from 0 to 9.