Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test;
- import java.util.Random;
- import java.util.Scanner;
- /**
- * <p>This is where you put your description about what this class does. You
- * don't have to write an essay but you should describe exactly what it does.
- * Describing it will help you to understand the programming problem better.</p>
- *
- * @author Your Name goes here
- * @version 1.0
- */
- public class Guess {
- /**
- * <p>This is the main method (entry point) that gets called by the JVM.</p>
- *
- * @param args command line arguments.
- */
- public static void main(String[] args) {
- int guess;
- int number;
- int count = 0;
- String again;
- boolean playAgain = true;
- Scanner scan = new Scanner(System.in);
- Random random = new Random();
- number = random.nextInt(100) + 1;
- guess = -1;
- while (playAgain) {
- if (guess != number) {
- System.out.println ("Guess a number from 0-100: ");
- guess = scan.nextInt();
- if (guess > number) {
- System.out.println ("Too high, try again.");
- count++;
- } else if (guess < number) {
- System.out.println ("Too low, try again.");
- count++;
- } else if (guess == number) {
- System.out.println(guess + " was correct.");
- System.out.println("It took you " + count + " tries.");
- playAgain = false;
- }
- }
- System.out.println("Woud you like to play again? (y/n)");
- again = scan.next();
- if (again.equalsIgnoreCase("n")) playAgain = false;
- }
- System.out.println("Question two was called and ran sucessfully.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement