I've been up for a few hours trying to find a solution.
My program asks the user to enter a list of integers (example: 5 2 5 6 6 1). Then I would like to create an array and store each integer into its respective array index, consecutively.
Here is the part of my program i'm having trouble with (this program was meant to perform calculations via a method later on, but I didn't include that):
import java.util.Scanner;
public class Assignment627 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int x = 0;
int[] list1Array = new int[1];
System.out.println("Enter list1: ");
while (input.hasNext()){
list1Array[x] = input.nextInt();
x++;
}
As you can see, I am instantiating the array "list1Array" but the problem is I don't know how many integers the user would enter! If only there were a way of knowing how many integers have been input... Any help would be greatly appreciated! Thanks, Sebastian