import java.util.Random; import java.util.Scanner; public class guessnum{ public static void main(String[] args){ Scanner scanner = new Scanner(System.in); Random random = new Random(); int cnt = 0; int guess = -1; int target = random.nextInt(1024) + 1; while(guess != target){ System.out.println("Input Your Guess:"); if(scanner.hasNextInt()){ int tmp = scanner.nextInt(); cnt++; if(guess < target){ System.out.println("It's Smaller than the word"); } else if(guess > target){ System.out.println("It's Bigger than the word"); } else { System.out.println("You've Guessed Right with " + cnt + " Attempts"); } } } scanner.close(); } }