forked from fenniless/BlueJ.TooLargeTooSmall
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
60 lines (56 loc) · 1.69 KB
/
Main.java
File metadata and controls
60 lines (56 loc) · 1.69 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
* Write a description of class Main here.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.util.Scanner;
import java.util.Random;
public class Main
{
// instance variables - replace the example below with your own
private int x;
/**
* Constructor for objects of class Main
*/
public Main()
{
game();
}
/**
* An example of a method - replace this comment with your own
*
* @param y a sample parameter for a method
* @return the sum of x and y
*/
public static void game()
{
boolean answer = false;
int count = 0;
int randomNumber = (int)(Math.random()*100 + 1);
int dummy = -1;
while(!answer) {
Scanner in = new Scanner(System.in);
System.out.println("\nEnter a number between 0 and 100, if you dare");
int guess = in.nextInt();
if(guess != dummy){
count++;
}
dummy = guess;
if(guess < 0 || guess > 100) {
System.out.print("Please enter a number between 0 and 100 ");
}
else if(guess < randomNumber) {
System.out.print("Your guess is to low ");
}
else if(guess == randomNumber) {
System.out.print("Winner ");
answer = true;
}
else if (guess > randomNumber) {
System.out.print("Your guess is too high");
}
}
System.out.print("congrats you guessed " + randomNumber + " in " + count + " guesses");
}
}