-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNumberGuess.java
More file actions
32 lines (29 loc) · 1007 Bytes
/
Copy pathNumberGuess.java
File metadata and controls
32 lines (29 loc) · 1007 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
import java.lang.Math;
import java.util.Scanner;
public class NumberGuess {
public static void main(String[] args) {
double rand = Math.random();
double i = rand *100;
int computer = (int) i ;
Scanner sc = new Scanner(System.in) ;
int score = 1;
while(true){
System.out.println("Guess the number between (1-100) :- ");
int guess= sc.nextInt();
if (guess > computer){
System.out.println("Try something Less...");
System.out.println(" ");
}
else if (guess == computer)
{
System.out.printf("You Guess Correctely !! You required Chance to Guess are :- %d " , score);
return ;
}
else {
System.out.println("Try something Higher...");
System.out.println(" ");
}
score++;
}
}
}