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
96 lines (64 loc) · 1.92 KB
/
Main.java
File metadata and controls
96 lines (64 loc) · 1.92 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
* Write a description of class Main here.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.util.Random;
import java.util.Scanner;
public class Main
{
// instance variables - replace the example below with your own
//private int x;
/**
* Constructor for objects of class Main
*/
public static void Main()
{
captureGuess();
}
/**
* 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 captureGuess()
{
int counter=0;
Random ran_num = new Random();
int number = ran_num.nextInt(10);
Scanner num = new Scanner(System.in);
System.out.println("Guess and Enter a number between 1 and 10");
int guess = num.nextInt();
int pre_guess=0;
while(guess!= number) {
if(guess>number && guess>=0 && guess<=10) {
System.out.println("Your Guess is too High Try again and Enter a number between 1 and 10");
//if ()
//guess=num.nextInt();
//counter++;
}
else if (guess<number && guess>=0 && guess<=10) {
System.out.println("Your Guess is too Low Try again and Enter a number between 1 and 10");
//if ()
//guess=num.nextInt();
//counter++;
}
else if (guess>10 || guess<0) {
System.out.println("Your Guess is Invalid Try again and Enter a number between 1 and 10");
//if ()
//guess=num.nextInt();
//counter++;
}
if (pre_guess!=guess){
counter++;
}
pre_guess=guess;
guess=num.nextInt();
}
System.out.println("Your Guess is correct and you guessed " + (counter+1)+" times");
//break;
}
}
//return x + y;