Guessing Game

/** * Write a description of class guessingGame here. * * @author (Alex Lee) * @version (09/11/17) */ import java.util.*; public class guessingGame { public static void main(String args[]){ int rnd; //random int guessInt; //player's guess boolean tryAgain = true; String playAgain; Scanner scan = new Scanner(System.in); System.out.println("This is the one and only guessing game"); while(tryAgain){ int tries = 3; rnd=(int) (Math.random( ) * (10)) + 1;//random number generator code guessInt = 0; int win = 0; System.out.println("Please guess a number between 1 and 10"); while(win == 0 && tries != 0){ guessInt = scan.nextInt(); System.out.println(); if(rnd == guessInt){ win = 1; } else if (tries >=0){ tries--; System.out.println("Wrong!"); } if (tries > 1){ System.out.println(tries + " tries remaining."); }else{ System.out.println("1 try remaining."); } }//end of while 1 if(win == 1){ System.out.println("You Win!!!" + rnd + "."); }else{ System.out.println("You Lose"); } System.out.println("to play again, press 1. Press any other key to exit."); System.out.println(); int cont = scan.nextInt(); if(cont != 1){ tryAgain = false; } }//end of while 2 }//end of static }//end of class
This took too long for me.

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.