Advertisement
Guest User

Untitled

a guest
Sep 16th, 2014
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.48 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("Your guess is too high. Guess again: ");
  35.             }
  36.             else
  37.             {
  38.                 System.out.println("Your guess is too low. Guess again: ");
  39.             }
  40.             guess = input.nextInt();    
  41.            
  42.         }
  43.    
  44.         System.out.println("You've guessed correctly!");
  45.         System.out.println("Your total number of high guesses: ");
  46.         System.out.println("Your total number of low guesses: ");
  47.         System.out.println("Your total number of wrong guesses: ");
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement