GuessingGame

/** * Write a description of class guessingGame here. * * @author (your name) * @version (a version number or a date) */ import java.util.*; public class guessingGame { public static void main(String args[]){ { Scanner sc = new Scanner(System.in); boolean ingame=true; while (ingame){ int random = (int )(Math.random() * 10 + 1); int end=0; String playAgain; System.out.println("This is the one and only guessing game"); System.out.println("Please guess a number between 1 and 10"); int input = sc.nextInt(); if(random==input){ System.out.println("Correct! The number was: " +random + " You Win!"); System.out.println("Would you like to play again? Press 1 to continue or 2 to exit"); end = sc.nextInt(); if(end==1){ ingame = true; }else{ ingame = false; System.exit(0); } }else{ System.out.println("Incorrect! You lose!"); System.out.println("Would you like to play again? Press 1 to continue or 2 to exit"); end = sc.nextInt(); if(end==1){ ingame =true; }else{ ingame =false; System.exit(0); } } } } } }//

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.