/* *Com S 207 *Hw 6 *NumGuess.java */ import java.util.Scanner; import java.util.Random; public class NumGuess { public static void main(String[]args) { Random rand = new Random(); Scanner scan = new Scanner(System.in); int number = rand.nextInt(100) + 1; int guess, round = 1; System.out.print("I'm thinking of a number between 1 and 100, take a guess: "); guess = scan.nextInt(); int cmd = 1; do{ if (guess == number){ System.out.println("You got it in " + round + " rounds."); System.out.print("Enter 1 to play again, 0 to quit: "); cmd = scan.nextInt(); if (cmd == 1){ number = rand.nextInt(100) + 1; System.out.print("I'm thinking of a number between 1 and 100, take a guess: "); guess = scan.nextInt(); } } else if (guess < number){ System.out.print("Higher, try again: "); guess = scan.nextInt(); round++; } else { System.out.print("Lower, try again: "); guess = scan.nextInt(); round++; } }while (cmd != 0); } }