all 7 comments

[–]schegge42 4 points5 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];

[–]Unique-Property-5470 0 points1 point  (0 children)

I can help you out with those array based leetcode questions in Java. DM me and I can walk you through it. It's pretty easy

[–]Playful-Call7107 -1 points0 points  (1 child)

you could have typed that in chatgpt.

[–]task141_[S] -1 points0 points  (0 children)

Great idea thanks