Assignment #49

Code

  /// Name: Sam Wilson
  /// Period: 6
  /// Program Name: guessgamept2
  /// File Name: guessgamept2.java
  /// Date Finished: 12/1/2015

     import java.util.Scanner;
import java.util.Random;
    
    public class guessgamept2
    {
        public static void main(String[] args)
        {
            
            Random s = new Random();
            Scanner key = new Scanner(System.in);

            
            int i;
            int choice = 1 + s.nextInt(10);
            
            
            System.out.print("I'm thinking of a number between 1 and 10 try to guess it: ");
            i = key.nextInt(); 
            System.out.println();
            System.out.println("Your guess: " +i);
            
            if (choice == i)
            {
                System.out.println("You guessed correctly! It was: " +choice);
            }
            
            else
            {
                System.out.println("Sorry you guessed wrong the answer was: "+choice);
            }
        }
    }

    

Picture of the output

Assignment 31