Name: Anonymous 2006-11-07 1:10
guys im trying to create a simulation of the lottery using java... i am makin an array consisting of 5 random numbers ranging from 0 to 9 the thing is i can only get the amount of arrays the class has and everytime i run the application all i get for the 5 random numbers are a bunch of zeros.
this is my code so far...
import java.util.Scanner;
import java.util.Random;
public class Lottery
{
public static void main (String[] args)
{
int[] lotteryNumbers = new int[5];
int indx;
int num1, num2, num3, num4, num5;
Random rand = new Random();
int sum = 0;
Scanner key = new Scanner(System.in);
System.out.println("The array size is " + lotteryNumbers.length);
for (indx = 0; indx <5; indx++)
{
num1 = rand.nextInt(9);
num2 = rand.nextInt(9);
num3 = rand.nextInt(9);
num4 = rand.nextInt(9);
num5 = rand.nextInt(9);
System.out.println(lotteryNumbers[indx]);
}
i forgot to mention the user also has to input his own 5 numbers to see if he won the "grand prize". but i think i have that part down for now... all i am really interested in are those damn 5 random numbers which i cant seem to get right... any help would be appreciated.
this is my code so far...
import java.util.Scanner;
import java.util.Random;
public class Lottery
{
public static void main (String[] args)
{
int[] lotteryNumbers = new int[5];
int indx;
int num1, num2, num3, num4, num5;
Random rand = new Random();
int sum = 0;
Scanner key = new Scanner(System.in);
System.out.println("The array size is " + lotteryNumbers.length);
for (indx = 0; indx <5; indx++)
{
num1 = rand.nextInt(9);
num2 = rand.nextInt(9);
num3 = rand.nextInt(9);
num4 = rand.nextInt(9);
num5 = rand.nextInt(9);
System.out.println(lotteryNumbers[indx]);
}
i forgot to mention the user also has to input his own 5 numbers to see if he won the "grand prize". but i think i have that part down for now... all i am really interested in are those damn 5 random numbers which i cant seem to get right... any help would be appreciated.