java - How to display elements of an array? -
I'm still learning Java and I was wondering how can I use an array element? For example, I have this array:
private int [employee name = {5658845, 4520125, 78 9 522, 8777541, 1302850, 758048 9};
And I want to display the number using the "450125" loop. What should I do? Besides, if you have a better way to loop, please do not hesitate to put it; It would be much appreciated. I will just put it in the loop for use in that situation:
for (int i = 0; i If you want to display the second element in an array, To: arrayName [indexNumber]
In your case, you will need to use this syntax:
Carmenum [1]
An index (such as "index number" and "1" are described above) is only an address. There is a variable representing the number one before and a later number. Imagine, on the right side of the given road, you had ten houses, if you would explain to someone else how to move to the right at the other house, Some would say:
houses [1]
Why do I '1' instead of '2'?
Because, in programming, you start calculating '0' instead of '1'.
I hope this helps. Be sure to up-vote comments that are helpful, and mark the best answer.
Comments
Post a Comment