Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner keyboard = new Scanner(System.in);
- int num = 50;
- int guesses = 1;
- System.out.println("I'm thinking of a number between 1-100. You have 7 tries.");
- System.out.println("First guess: ");
- int guess = keyboard.nextInt();
- guesses++;
- while(guess != num && guesses < 8){
- if(guess > num){
- System.out.println("Sorry, that guess is too high");
- }
- if (guess < num) {
- System.out.println("Sorry, that guess is too low");
- }
- System.out.println("Guess # " +
- guesses);
- guesses++;
- guess = keyboard.nextInt();
- }
- if(guesses == 8){
- System.out.println("sorry you didn't guess it in 7 tries. You lose.");
- } else{
- System.out.println("You guessed it!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement