Advertisement
lol1234561

Untitled

Mar 10th, 2023
789
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.00 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Main {
  3.     public static void main(String[] args) {
  4.         Scanner keyboard = new Scanner(System.in);
  5.         int num = 50;
  6.         int guesses = 1;
  7.         System.out.println("I'm thinking of a number between 1-100. You have 7 tries.");
  8.         System.out.println("First guess: ");
  9.         int guess = keyboard.nextInt();
  10.         guesses++;
  11.  
  12.         while(guess != num && guesses < 8){
  13.             if(guess > num){
  14.                 System.out.println("Sorry, that guess is too high");
  15.             }
  16.             if (guess < num) {
  17.                 System.out.println("Sorry, that guess is too low");
  18.             }
  19.             System.out.println("Guess # " +
  20.                     guesses);
  21.             guesses++;
  22.             guess = keyboard.nextInt();
  23.  
  24.         }
  25.         if(guesses == 8){
  26.             System.out.println("sorry you didn't guess it in 7 tries. You lose.");
  27.         } else{
  28.             System.out.println("You guessed it!");
  29.         }
  30.  
  31.     }
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement