-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathguessing_game.java
More file actions
37 lines (37 loc) · 1.18 KB
/
Copy pathguessing_game.java
File metadata and controls
37 lines (37 loc) · 1.18 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
//Number Guessing Game
import java.lang.Math;
import java.util.Scanner;
class Guess{
public static void main(String[] args){
int guessNum=(int)Math.random()*100;
int num,counter=0;
boolean won=false;
while(true){
System.out.println("Enter your Guess: ");
Scanner scan=new Scanner(System.in);
num=scan.nextInt();
System.out.println("You Guess: ");
System.out.println(num);
counter++;
if(num==-1){
break;
}
if(num > guessNum){
System.out.println("Very Large! ");
}
else if(num < guessNum){
System.out.println("Very Small! ");
}
else{
won=true;
break;
}
}
if(won){
System.out.println("Congratulations, You guessed it correctly!");
System.out.println("You have got the number" + " " + num +" "+ "correctly after" +" "+ counter +" "+ "tries!");}
else{
System.out.println("Better luck next time!");
}
System.out.println("Thanks for playing!");
}}