Assignment 52

Code

    import java.util.Scanner;

    public class NumberGuessing
    {
        public static void main(String[] args)
        {
            Scanner keyboard = new Scanner(System.in);
            
            int secretNumber = 7;
            int guess;
            
            System.out.println("guess a number.");
            System.out.println();
            
            System.out.println("It's between 1 and 10. ");
            guess = keyboard.nextInt();
            
            System.out.println();
            
            if (guess == secretNumber)
                System.out.println("Nice, you guessed it.");
            else
                System.out.println("Sorry, I was thinking of was " + secretNumber + ".");
        }
    }
    

Picture of the output

Assignment