Something went wrong with my code.
import java.util.Random; import java.util.Scanner; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ public class GuessingGameByIanNeumann { private static String msg; public static void main(String[] args) { Random any = new Random(); Scanner input = new Scanner (System.in); do { int maxNum, maxTries, userGuess; boolean win = false; String doAgain = "n"; try { maxNum = any.nextInt(100); maxTries = 0; while (win == false) { System.out.print("\n" + "Pick a number between 1 and 10: "); userGuess = input.nextInt(); maxTries++; if (userGuess == maxNum) { win = true; } else if (userGuess < maxNum) { System.out.println("\n" + "The number you picked is TOO LOW."); } else if (userGuess > maxNum) { System.out.println("\n" + "The number you picked is TOO HIGH."); } } System.out.println("\n" + "YOU WIN! The number was: " + maxNum + "\n"); System.out.println("It took this many tries to get it right: " + maxTries + "\n"); catch { input.next(); System.out.println("Sorry, invalid input- " + msg + " exception try again "); } } while(doAgain.equalsIgnoreCase("y")); } }
Something went wrong and I got all mixed up. Can anyone help fix this for me, please?