Assignment #55

Code

  /// Name: Sam Wilson
  /// Period: 6
  /// Program Name: whileguessin
  /// File Name: whileguessin.java
  /// Date Finished: 12/7/2015

   import java.util.Scanner;
  import java.util.Random;
      
      public class whileguessin
      {
          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);
              
              while (choice != i)
              {
                  System.out.println("You guessed incorrectly! Try Again.");
                  System.out.println();
                  System.out.print("> ");
                  i = key.nextInt();
                   
                                     
              }
              
              System.out.println("Congrats you guessed correctly!");
          }
      }
    

Picture of the output

Assignment 31