@@ -0,0 +1,1259 @@
+import java.util.Random;%0D%0Aimport java.util.Scanner;%0D%0A%0D%0A/*%0D%0A * Guess the number game in Java%0D%0A */%0D%0Apublic class GuessTheNumber %7B%0D%0A%09public static void main(String%5B%5D args) %7B%0D%0A%09    Scanner in = new Scanner(System.in); // Import scanner%0D%0A%09    // Generate a random answer%0D%0A%09    Random r = new Random(); %0D%0A%09    int ans = r.nextInt(100) + 1;%0D%0A%09    // Initialize attempts and guess value%0D%0A%09    int attempts = 1; %0D%0A%09    int guess = -1; %0D%0A%09    System.out.println(%22I am thinking of a number between 0 and 100.%22);%0D%0A%09    // Keep looping until user has guessed the number%0D%0A%09    while (true) %7B%0D%0A%09    %09System.out.println(%22Enter a guess: %22);%0D%0A%09    %09guess = in.nextInt(); // Get the user's guess %0D%0A%09    %09if (ans %3E guess) %7B // If the guess is too high%0D%0A%09            System.out.println(%22Your number is too low!%22);%0D%0A%09            attempts += 1; %0D%0A%09        %7D%0D%0A%09        else if (ans %3C guess)%7B // If the guess is too low%0D%0A%09            System.out.println(%22Your number is too high!%22);%0D%0A%09            attempts += 1;%0D%0A%09        %7D %0D%0A%09        else %7B // If the user has guessed the answer%0D%0A%09        %09break;%0D%0A%09        %7D%0D%0A%09    %7D%0D%0A%09    // Return answer and number of attempts%0D%0A%09    System.out.println(ans + %22 is the correct answer! You took %22 + attempts + %22 tries to guess the number!%22); %0D%0A%09%7D%0D%0A%7D%0D%0A

Add number guessing game