Загрузка данных


import java.util.Scanner;
import java.util.Random;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Random random = new Random();

        while (true) {
            System.out.println("1 - Запустить игру");
            System.out.println("2 - Выход");
            System.out.print("Выбор: ");

            if (!scanner.hasNextInt()) {
                System.out.println("Нужно число");
                scanner.next();
                continue;
            }

            int choice = scanner.nextInt();

            if (choice == 2) {
                System.out.println("Выход");
                break;
            }

            if (choice != 1) {
                System.out.println("Неверный выбор");
                continue;
            }

            while (true) {
                int secret = random.nextInt(11);
                int tries = 0;
                boolean win = false;

                while (tries < 3) {
                    System.out.print("Введите число от 0 до 10: ");

                    if (!scanner.hasNextInt()) {
                        System.out.println("Ошибка. Надо вводить только числа от 0 до 10");
                        scanner.next();
                        continue;
                    }

                    int guess = scanner.nextInt();

                    if (guess < 0 || guess > 10) {
                        System.out.println("Ошибка. Надо вводить только числа от 0 до 10");
                        continue;
                    }

                    tries++;
                    int cmp = Integer.compare(guess, secret);

                    if (cmp == 0) {
                        System.out.println("Вы угадали!");
                        win = true;
                        break;
                    }
                    if (cmp < 0) {
                        System.out.println("Загаданное число больше");
                    } else {
                        System.out.println("Загаданное число меньше");
                    }
                }

                if (!win) {
                    System.out.println("Попытки кончились. Было число: " + secret);
                }

                int again = 0;
                while (true) {
                    System.out.println("Хочешь еще сыграть?");
                    System.out.println("1 - да хочу рискнуть");
                    System.out.println("2 - нет");
                    System.out.print("Выбор: ");

                    if (!scanner.hasNextInt()) {
                        System.out.println("Ошибка - введите только 1 или 2");
                        scanner.next();
                        continue;
                    }

                    again = scanner.nextInt();

                    if (again == 1 || again == 2) break;

                    System.out.println("Ошибка - введите только 1 или 2");
                }

                if (again == 2) break;
            }
        }
    }
}