/** * Created by iyasuwatts on 10/17/17. */ import java.util.Random; import java.util.Scanner; public class Main { public static void game() { Random rand = new Random(); Scanner scan = new Scanner(System.in); // int answer = rand.nextInt(11); int answer = 2; String prevGuess = "-1337"; int guessCount = 1; System.out.println("Guess my number between 0 - 10."); String guess = scan.nextLine(); while (Integer.parseInt(guess) != answer) { if (!guess.equals(prevGuess)) guessCount++; String output = Integer.parseInt(guess) == Integer.parseInt(prevGuess) ? "That was the same guess as before... try again: " : Integer.parseInt(guess) < 0 || Integer.parseInt(guess) > 10 ? "It's between 0-10. Try again: " : Integer.parseInt(guess) == answer ? "reset" : Integer.parseInt(guess) > answer ? "Too much. Try again: " : Integer.parseInt(guess) < answer ? "Too little. Try again: " : null; System.out.println(output); prevGuess = guess; guess = scan.nextLine(); } System.out.println("Total guess count: " + guessCount); System.out.println("You won! Would you like to play again? (Y/N)"); String playAgain = scan.nextLine(); if (playAgain.toLowerCase().equals("y")) game(); System.out.println("Now shutting down."); } public static void main(String[] args){ game(); } }