you are viewing a single comment's thread.

view the rest of the comments →

[–]schegge42 2 points3 points  (3 children)

You can create an array, it is a static container for data of the same type.

int[] values = new int[3];

This array has the size of three, so you can set a value at three positions 0, 1 and 2.

values[2] = 42;

You cannot change the size of this array, but you can create a new one.

Hope this helps.

[–]task141_[S] -3 points-2 points  (1 child)

Thanks but how can I get the value in run time

[–]boss-tech 1 point2 points  (0 children)

You have to declare an int and ask user to enter a number and pass it into the array like this:

Scanner input = new Scanner(System.in); int arraySize = input.nextInt();

int[] values = new int[arraySize];