forked from THartmanOfTheRedwoods/Java-Assignment-003
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJava-Assignment-003.iml
More file actions
25 lines (22 loc) · 909 Bytes
/
Copy pathJava-Assignment-003.iml
File metadata and controls
25 lines (22 loc) · 909 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import java.util.Random;
import java.util.Scanner;
/**
* Starter code for the "Guess My Number" exercise.
*/
public class GuessStarter {
public static void main(String[] args) {
String newLine = System.lineSeparator();
Scanner numInput = new Scanner(System.in);
System.out.println("I'm thinking of a number between 1 and 100." + newLine + "Can you guess what it is?");
// pick a random number
int userGuess = numInput.nextInt();
System.out.println("Your Guess is:" + userGuess + "?");
Random random = new Random();
int number = random.nextInt(100) + 1;
System.out.println(number);
System.out.println("The number that I was thinking of is:" + number);
int difference = Math.abs(userGuess - number);
//Absolute value of difference
System.out.println("Your guess was off by: " + difference);
}
}