1
I need to store values with more than one entry. If a program requests 10 entries, should I store them in 10 variables? In this case the entries are of the type Int
.
1
I need to store values with more than one entry. If a program requests 10 entries, should I store them in 10 variables? In this case the entries are of the type Int
.
4
Yes, you must, but understand what a variable.
Doubt does not talk about what values will be entered, but it is likely that these variables are of the type int
, since for exercises like this usually ask only integer numerical values.
But most likely, you’re expected to use a array. A variable of the type array is the one that stores other variables in sequence. Then we will have 11 variables, 1 for the array and 10 for whole foods.
In typed languages, like Java, all variables have types in everything. So you have a array whole.
When we’re wearing one array we are talking about accessing a value that depends on variations: one is the array and another is the data itself. So to access a array just use the variable name, but to access the value you need to use the variable name of the array and the index indicating which variable will be used.
So let’s create the array of the kind int
10-position.
int[] array = new int[10];
Now to access his first variable we use:
array[0]
For the second:
array[1]
Until the last:
array[9]
This is how to access array0
, array1
, array9
, But if you used the names like this the index couldn’t vary and that makes the application very flexible. With the index it is possible to use a variable in it, thus:
array[i]
I put in the Github for future reference.
What position is picking up? The one that variable i
indicate, vary, and this is the beauty of computing. So you can manipulate 10 variables in up to one line by making a loop.
You’re not getting used to array, noose (loop), these things? There is a lot of information here on the site that can help you, gives a search.
Browser other questions tagged java array
You are not signed in. Login or sign up in order to post.
This is a question for very beginner programmers. The answer will depend a lot on the goal of storing the 10 entries.
– Sveen
Use an Array, or other data structure.
– Sveen
Thanks for the help, the problem was in the control structures and not in the storage of variables.
– D.rosario
@D.Osario Has the answer solved your question? Do you think you can accept it? See [tour] if you don’t know how to do it. This would help a lot to indicate that the solution was useful for you. You can also vote on any question or answer you find useful on the entire site (when you have 15 points, you will have to accept the answer).
– Maniero