# Java Question



## dcf-joe (Dec 23, 2008)

I need help creating a program that takes input from the user, stores it into an array, and then combines everything in the end. Here is the first part of the program, but I do not know what to do next. I may even be going in the wrong direction. But, here it is:
import java.util.Scanner;

public class Gauss
{
	public static void main(String[] args)
	{
		Scanner reader = new Scanner(System.in);
		System.out.print("Enter the number of times the loop should run: ");
			int num3 = reader.nextInt();

		int[] ia = new int[num3];

		for (int i = 0; i < ia.length; i++)
		{
			ia_ = i;
		}

		int sum = 0;

		for (int i = 0; i < ia.length; i++)
		{
			sum += ia;
		}
		System.out.println(sum);
	}
}_


----------



## Oliver_FF (Dec 24, 2008)

In Java you shouldn't be using Arrays, you should use a Collection:


```
import java.util.*;

public class Gauss
{
    public static void main(String[] args)
    {
        //Create an arraylist of Strings. This is our collection.
        ArrayList<String> inputLines = new ArrayList<String>();
        //Create a scanner to read from the console.
        Scanner reader = new Scanner(System.in);

        //Start looping
        do {
            //Get the user input
            String currentLine = reader.nextLine();
            //Add it to the collection
            inputLines.add(currentLine);
        //keep looping until they don't enter anything
        } while (currentLine != null || currentLine.length()!=0); 
        
        //Loop over every String in the collection and print it out...
        for (String s: inputLines) {
            System.out.print(s);
        }
    }
}
```


----------

