-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextGame.java
More file actions
40 lines (32 loc) · 928 Bytes
/
TextGame.java
File metadata and controls
40 lines (32 loc) · 928 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import java.util.Scanner;
public class TextGame {
public static void main(String[] args) {
int magicNumber = 42;
int guess = 0;
System.out.println();
System.out.println("Welcome to the Magic Number Game!");
System.out.println();
while (guess != magicNumber){
guess = readInt("Take a guess ");
if(guess != magicNumber){
System.out.println("Nope that's not correct :(");
if(guess - magicNumber <= Math.abs(10)){
System.out.println("You're very close!");
System.out.println();
}
}
}
System.out.println();
System.out.println("Hurrah! You got the Magic Number!");
}
public static int readInt(String prompt) {
Scanner input = new Scanner(System.in);
System.out.println(prompt);
int guess = input.nextInt();
input.nextLine();
return guess;
}
public static String goToNextLine (String n) {
return " ";
}
}