-
Notifications
You must be signed in to change notification settings - Fork 0
/
NumberGuessing.java
43 lines (40 loc) · 1.49 KB
/
NumberGuessing.java
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
import java.util.*;
public class StackClass{
public static int k = 5;
public static void guesseingNumberGame(){
try (Scanner sc = new Scanner(System.in)) {
int number = 1+(int)(100*Math.random());
int points =0;
int i, guess;
System.out.println("A numbr is choosen" + "between 1 to 100" + "Guess the numnbr" + "within 5 trails.");
for( i = 0;i<k;i++){
System.out.println("Guess the number");
guess = sc.nextInt();
if(number == guess){
points += 10;
System.out.println(
"Congratulations!" +
" you guessed the number"
);
break;
}
else if(number>guess && i!= k-1){
System.out.println("The numnber is"
+ "greater then" + guess);
}
else if(number < guess && i!= k-1){
System.out.println("The numbr is"+
"less then" + guess);
}
}
if(i == k){
System.out.println("you have exhausted" + " k trails");
System.out.println("The number was" + number);
}
}
}
public static void main(String[] args) {
StackClass sc = new StackClass();
guesseingNumberGame();
}
}