Ok, here's what I got.
import java.util.Random; import java.util.Scanner; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ public class demoGuessGame { public static void main(String[] args) { Random any = new Random(); Scanner input = new Scanner (System.in); try { int maxNum, maxTries, guess; boolean win = false; maxNum = any.nextInt(10); maxTries = 0; while (win == false) { System.out.print("\n" + "Pick a number between 1 and 10: "); guess = input.nextInt(); maxTries++; if (guess == maxNum) { win = true; } else if (guess <= maxNum) { System.out.println("\n" + "The number you picked is TOO LOW."); } else if (guess >= maxNum) { System.out.println("\n" + "The number you picked is TOO HIGH."); } } System.out.println("\n" + "YOU WIN!"); System.out.println("The number was: " + maxNum); System.out.println("It took this many tries to get it right: " + maxTries); } // end of the try section catch(Exception msg) { input.next(); System.out.println("\n" + "Sorry, invalid input- " + msg + " exception try again "); } //end of the catch section } }
I want to make it loop again when asked, "Do you want to play again?"
But I don't know how. Does anyone know how to?