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

>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)
	    	System.out.print("Enter a number from 1-54 (pick #" + i + "): ");
	    	Scanner input = new Scanner(;
	    	int x = input.nextInt();
	    	int [] a = int[] x;
    	System.out.println("Playing the folowing six numbers: ");

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!

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.