So the prelab for my CSE class asks
Your assignment in version 1 is to write a Java program that lets you select six
lottery numbers. For this version, you can accept any six values including
duplicates. Your program must have the following elements:
- Create a class named Lottery1
- Use a loop to continue prompting for the six integers. Exit when all six values
have been captured.
- Use an array to store the six int values.
- After populating the array, use a loop to print out each of the values.
- Perform everything within the main method.
With output of

SAMPLE OUTPUT Version 1:
>java Lottery1
Enter a number from 1-54 (pick #1): 12
Enter a number from 1-54 (pick #2): 60
Enter a number from 1-54 (pick #3): 12
Enter a number from 1-54 (pick #4): 26
Enter a number from 1-54 (pick #5): 15
Enter a number from 1-54 (pick #6): 9
Playing the following six numbers:
12 60 12 26 15 9

So far I have

import java.util.Scanner;

class Lottery1
{
	static int x;
	static int [] a;

    public static void main(String [] args)
    {
    	int i = 0;
    	while (i < 6)
    	{
    		i++;
	    	System.out.print("Enter a number from 1-54 (pick #" + i + "): ");
	    	Scanner input = new Scanner(System.in);
	    	int x = input.nextInt();
	    	int [] a = int[] x;
    	}
    	System.out.println();
    	System.out.println("Playing the folowing six numbers: ");
    	System.out.print(a[x]);
    }
}

I need to fix my arrays so that what I input for each will print at the end. I've searched high and low to no avail... Please show me what my problem is!

Edited 5 Years Ago by peter_budo: Keep It Clear - Do use code tags when posting any code

1) Use i++ at the end, If you want to show user that please enter value one then use i+1 in print statement.
2) You need to set size for integer array before using it, int a[] = new int[6] // because you want to store 6 values
3) Take input in each array position a[position] = someintvalue
4) use for loop to print them all.
:)

This article has been dead for over six months. Start a new discussion instead.