/** * Created by iyasuwatts on 10/17/17. */ import java.util.*; public class Main { public static void main(String[] args){ Random randomNumber = new Random(); Scanner x = new Scanner(System.in); int computerNumber = randomNumber.nextInt(10); int numberOfTries = 0; int success = 0; int guess = 0; while (success ==0){ System.out.println("Guess a number from 1 to 10"); guess = x.nextInt(); numberOfTries++; if (guess < 1 || guess >10){ System.out.println("Invaled number. Try again"); } else if (guess == computerNumber){ System.out.println("Congratulations your right! Only took you " + numberOfTries + " tries."); } else if (guess < computerNumber){ System.out.println("Too low! Try again."); } else if (guess > computerNumber){ System.out.println("Too high! Try again."); } if (guess == computerNumber){ break; } } } }