Datasets:

ArXiv:
License:
File size: 1,073 Bytes
c574d3a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import java.util.Random;
import java.util.Scanner;

public class NumberGuess{
    public static void main(String[] args) {
        Random rand = new Random();
        int num = rand.nextInt(100);

        Scanner sc = new Scanner(System.in);

        for(int i=0;i<10;i++){
            System.out.println("Enter your guess Number: ");
            
            String chose = sc.nextLine();
            try{
                int choice = Integer.parseInt(chose);
                if(choice<num){
                    System.out.println("Smaller");
                } else if(choice<1 || choice>100){
                    System.out.println("Please enter number between 0 to 100");
                } else if(choice==num){
                    System.out.println("Your guess is correct");
                    break;
                } else{
                    System.out.println("Greater");
                }
            }
            catch(NumberFormatException e){
                System.out.println("Only enter numeric value");
            }
        }
        sc.close();
    }
}