Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package project2;
- /**
- *
- * @author gagikgarabigie
- */
- import java.util.Random; // loads in the library with the code to generate random numbers
- import java.util.Scanner; // asks user for input
- public class GuessingGame
- {
- public static void main(String[] args)
- {
- Random rand = new Random(); // creates a new Random object with which to work
- int value = rand.nextInt(35)+1; // this is the line of code that grabs the random number itself
- Scanner input = new Scanner(System.in);
- System.out.println("Guess the number I'm thinking of, from 1-36: ");
- int guess = input.nextInt();
- int too_high_Guess = 0;
- int too_low_Guess = 0;
- int total_Guesses = 0;
- while (value != guess)
- {
- if(guess > value)
- {
- System.out.println("Your guess is too high. Guess again: ");
- too_high_Guess++;
- }
- else
- {
- System.out.println("Your guess is too low. Guess again: ");
- too_low_Guess++;
- }
- guess = input.nextInt();
- }
- for(int total_asterisk = 0; guess == value; total_asterisk++)
- for(int low_asterisk = 0; guess < value; low_asterisk++)
- for(int high_asterisk = 0; guess > value; high_asterisk++)
- total_Guesses = too_high_Guess + too_low_Guess + 1;
- System.out.println("You've guessed correct!");
- System.out.println("Your total number of guesses: " + total_Guesses);
- System.out.println("Your total number of low guesses: " +too_low_Guess);
- System.out.println("Your total number of high guesses: " +too_high_Guess);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement