File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import java .util .Random ;
2+ import java .util .Scanner ;
23
3- /**
4- * Starter code for the "Guess My Number" exercise.
5- */
64public class GuessStarter {
7-
85 public static void main (String [] args ) {
6+ // introduce the guessing game
7+ System .out .println ("I'm thinking of a number between 1 and 100 (including both). " +
8+ "Can you guess what it is? " );
9+
10+ // ask for input
11+ Scanner in = new Scanner (System .in );
12+ System .out .print ("Type a number: " );
13+ int guess = in .nextInt ();
14+ System .out .println ("Your Guess is: " + guess );
15+
916 // pick a random number
1017 Random random = new Random ();
1118 int number = random .nextInt (100 ) + 1 ;
12- System .out .println (number );
19+ System .out .println ("The number I was thinking of is: " + number );
20+ int diff = Math .abs (guess - number );
21+ System .out .println ("You were off by: " + diff );
22+
1323 }
1424
1525}
26+
You can’t perform that action at this time.
0 commit comments