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(5)+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-6: ");
- int guess = input.nextInt();
- while (value != guess)
- {
- if(guess > value)
- {
- System.out.println("Your guess is too high. Guess again: ");
- }
- else
- {
- System.out.println("Your guess is too low. Guess again: ");
- }
- guess = input.nextInt();
- }
- System.out.println("You've guessed correctly!");
- System.out.println("Your total number of high guesses: ");
- System.out.println("Your total number of low guesses: ");
- System.out.println("Your total number of wrong guesses: ");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement