# Complete Noob -- A little help would be appreciated...

• March 5th, 2012, 03:37 PM
echmiel
Complete Noob -- A little help would be appreciated...
I'm seriously confused with the Random class in relation to the following question:

Write a program to prompt the user for three integers from 1 to 3. Using random numbers, print which number(s) are guessed correctly. Allow the user to continue to guess by inputting any incorrect number(s) until the user inputs an ‘n’ to quit the program, or the program displays “CONGRATULATIONS, ALL THREE NUMBERS WERE GUESSED CORRECTLY! THE NUMBERS WERE: 2, 2, 1.” The logic for the user would look like:

You may input an ‘n’ to quit the program at any time.

Number 1 is correct.

Is the following code randomly generating a number between 0-3 and, if so, what would the next step be to compare the randomly generated number to the user input? Here is the code:

import java.util.Scanner;
import java.util.Random;

public class Random
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner (System.in);

int number1;
int number2;
int number3;

Random randomNumbers = new Random()

number1 = randomNumbers.nextInt(3);
number2 = randomNumbers.nextInt(3);
number3 = randomNumbers.nextInt(3);

System.out.println("Please guess number 1. The number must be within zero and three. ";

ETC...

Any help is appreciated.

E
• March 5th, 2012, 04:31 PM
snowguy13
Re: Complete Noob -- A little help would be appreciated...