Hey everyone! I am a newbie to java and I have what is probably a simple question. I have add a program I am working on to randomly display random numbers from 104, 105, 106, and 108. I have gone about this by creating an array and storing the numbers i want to choose from in the array. Then I try to create a random number generator that references the array. But this is not working. So my questions are... Am i on the right track? Why will it not recognize the array? Should I be doing this differently?
Thank you all in advance! I realize this is probably a really simple question to a lot of your guys so thank you all for the help!
import java.util.Random;
public class NumberRandom1
{
public static void main( String[] args )
{
Random randomNumbers = new Random();// random number generator
int Number;// stores numbers as an int
int[] array = { 104, 105, 106, 108 };
// counter added for testing purposes
for ( int counter = 1; counter <= 1; counter++ )
{
// Pick random number number from
// 104, 105, 106, 108
Number = randomNumbers.nextInt( array );// this is my problem
System.out.printf( "%d ", Number );//display value
}
}