Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class MyFirstClass
- {
- public static void main(String[] args)
- {
- Scanner read = new Scanner(System.in);
- int randomNum = (int) (Math.random() * 100) + 1;
- System.out.println("I have chosen a number between [1-100]");
- System.out.println("Try to guess it and I'll help you do so!");
- System.out.println("Unfortunately you have only 10 guesses, so good luck!");
- int count=0;
- int guess;
- while (count<=10)
- {
- count++;
- System.out.println("Enter number: ");
- guess = read.nextInt();
- if (guess == randomNum)
- {
- System.out.println("YOU WON!");
- break;
- }
- else
- {
- System.out.println("Wrong, you got "+(10-count)+" left!");
- if (guess>randomNum)
- System.out.println("Number smaller than "+guess);
- else
- System.out.println("Number greater than "+guess);
- }
- }
- System.out.println("Good luck next try!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement