GuessingGame

/** * Write a description of class guessingGame here. * Guessing game, with 3 trees to find a # between 1 and 10 * @author (Rahul Khullar) * @version (9/8/17) */ import java.util.*; import java.util.Random; public class guessingGame { public static void main(String args[]) { int restarter = 1; while (restarter == 1){ Random rand = new Random(); String playAgain; Scanner scan = new Scanner(System.in); System.out.println("This is the one and only guessing game"); System.out.println("Please guess a number between 1 and 10"); int guessInt = scan.nextInt(); int max = 10; int min = 1; int randomNum = (int)(Math.random() * ((max - min) + 1)) + min; //inclusive System.out.println("Please make another guess"); int guessInt2 = scan.nextInt(); System.out.println("Please make another guess"); int guessInt3 = scan.nextInt(); if (guessInt == randomNum){ System.out.println("You guessed the correct number on guess #1, the correct number was: " + randomNum); } else if (guessInt2 == randomNum){ System.out.println("You guessed the correct number on guess #2, the correct number was: " + randomNum); } else if (guessInt3 == randomNum){ System.out.println("You guessed the correct number on guess #3, the correct number was: " + randomNum); } else { System.out.println("You guessed the wrong number, the correct number was: " + randomNum); } System.out.println("press 1 to play agin, press another anything else to quit"); int decider = scan.nextInt(); if (decider == 1){ restarter = 1; } else { restarter = 2; } } } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.