GuessingGame

/** * Write a description of class guessingGame here. * * @author (your name) * @version (a version number or a date) */ 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 rnd = rand.nextInt(10) + 1; System.out.println("Please make another guess"); int guessInt2 = scan.nextInt(); System.out.println("Please make another guess"); int guessInt3 = scan.nextInt(); if (guessInt == rnd){ System.out.println("You guessed the correct number on guess #1, the correct number was:" + rnd); } else if (guessInt2 == rnd){ System.out.println("You guessed the correct number on guess #2, the correct number was:" + rnd); } else if (guessInt3 == rnd){ System.out.println("You guessed the correct number on guess #3, the correct number was:" + rnd); } else { System.out.println("You guessed the wrong number, the correct number was:" + rnd); } 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.