Difference between revisions of "Guess my Number"

From CompSciWiki
Jump to: navigation, search
Line 10: Line 10:
 
|SideSection=
 
|SideSection=
 
[[Image:Wiki_loops01.jpg|center]]
 
[[Image:Wiki_loops01.jpg|center]]
 +
<BR>
  
 
|Solution=To get a random number in java you need to include the following statement at the beginning of your source code. <pre>import java.util.Random;</pre>
 
|Solution=To get a random number in java you need to include the following statement at the beginning of your source code. <pre>import java.util.Random;</pre>

Revision as of 15:21, 6 April 2010

Back to the Program-A-Day homepage

Problem

Generate a program where the computer chooses a random number between 1 and 10 and the user is continuously asked to guess it until they are correct.

You will need to review [JOptionPane for input and ouput]

 

While and For Loops

Wiki loops01.jpg


Solution

To get a random number in java you need to include the following statement at the beginning of your source code.
import java.util.Random;

Code

Solution Code

Back to the Program-A-Day homepage