Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- import java.util.Scanner;
- public class GuessingGame {
- public static void main(String[] args){
- int guess;
- Scanner sc = new Scanner(System.in); //Gets user input
- Random rnd = new Random(); //Generates a random number
- int number = rnd.nextInt(11); //Converts random number object to an int
- System.out.println("Guess a number between 0 and 10: ");
- guess = sc.nextInt();
- if(guess == number){
- System.out.println("Congratulations, you guessed right");
- }else{
- System.out.println("You guessed wrong, congratulations!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement