Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- import java.util.Scanner;
- public class NumberGuess {
- public static void main(String args[]){
- Scanner scan = new Scanner(System.in);
- Random rand = new Random();
- int answer, guess, tries = 0;
- answer = rand.nextInt(10)+1;
- System.out.println("I am thinking of a number from 1 to 10");
- System.out.println("You must guess what it is in three tries");
- while (tries <= 3){
- while (guess != answer){
- System.out.println("Enter a guess: ");
- guess = scan.nextInt;
- if (guess == answer){
- System.out.println("CORRECT!");
- }else{
- System.out.println("Sorry, please guess again");
- }
- tries = tries +1;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement