Advertisement
Guest User

Untitled

a guest
Sep 16th, 2014
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.98 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(35)+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-36: ");
  27.         int guess = input.nextInt();
  28.         int too_high_Guess = 0;
  29.         int too_low_Guess = 0;
  30.         int total_Guesses = 0;
  31.        
  32.        
  33.         while (value != guess)
  34.         {
  35.  
  36.             if(guess > value)
  37.             {
  38.                 System.out.println("Your guess is too high. Guess again: ");
  39.                 too_high_Guess++;
  40.             }
  41.             else
  42.             {
  43.                 System.out.println("Your guess is too low. Guess again: ");
  44.                 too_low_Guess++;
  45.             }
  46.            
  47.             guess = input.nextInt();
  48.            
  49.         }
  50.        
  51.         for(int total_asterisk = 0; guess == value; total_asterisk++)
  52.         for(int low_asterisk = 0; guess < value; low_asterisk++)
  53.         for(int high_asterisk = 0; guess > value; high_asterisk++)
  54.    
  55.         total_Guesses = too_high_Guess + too_low_Guess + 1;
  56.        
  57.         System.out.println("You've guessed correct!");
  58.         System.out.println("Your total number of guesses: " + total_Guesses);
  59.         System.out.println("Your total number of low guesses: " +too_low_Guess);
  60.         System.out.println("Your total number of high guesses: " +too_high_Guess);
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement