Java console game, guess the number.

mail@pastecode.io avatar
unknown
java
a year ago
1.1 kB
1
Indexable
Never
import java.util.Scanner;
import java.lang.Math;

public class GuessTheNumber {
    public static void main(String[] args) {
        final int number = (int) (Math.random() * 10 + 1);
        final Scanner scanner = new Scanner(System.in);
        
        System.out.println("-------------------");
        System.out.println(" GUESS THE NUMBER ");
        System.out.println("-------------------");
        System.out.println("-------------------");
        System.out.println("");
        System.out.println("More => true");
        System.out.println("Less => false");
        System.out.println("");
        
        while (scanner.hasNextInt()) {
            int i = scanner.nextInt();
        
            if (number == i) {
                System.out.println("-------------------");
                System.out.println("¡Winner! -> " + i);
                System.out.println("-------------------");
                scanner.close();
                return;
            }
            
            System.out.println(number > i);
        }
    }
}