Advertisement
Guest User

Untitled

a guest
Sep 16th, 2014
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.61 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6.  
  7. package project2;
  8.  
  9. /**
  10.  *
  11.  * @author gagikgarabigie
  12.  */
  13.  
  14. import java.util.Random; // loads in the library with the code to generate random numbers
  15. import java.util.Scanner; // asks user for input
  16.  
  17. public class GuessingGame
  18. {
  19.    
  20.     public static void main(String[] args)
  21.     {
  22.         Random rand = new Random(); // creates a new Random object with which to work
  23.         int value = rand.nextInt(5)+1; // this is the line of code that grabs the random number itself
  24.        
  25.         Scanner input = new Scanner(System.in);
  26.         System.out.println("Guess the number I'm thinking of, from 1-6: ");
  27.         int guess = input.nextInt();
  28.        
  29.         while (value != guess)
  30.         {
  31.  
  32.             if(guess == value)
  33.             {
  34.                 System.out.println("Correct, the number is " +value);
  35.             }
  36.             else if(guess > value)
  37.             {
  38.                 System.out.println("Your guess is too high. Guess again: ");
  39.             }
  40.             else
  41.             {
  42.                 System.out.println("Your guess is too low. Guess again: ");
  43.             }
  44.             guess = input.nextInt();    
  45.            
  46.         }
  47.    
  48.         System.out.println("You've guessed correctly!");
  49.         System.out.println("Your total number of high guesses: ");
  50.         System.out.println("Your total number of low guesses: ");
  51.         System.out.println("Your total number of wrong guesses: ");
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement