java - Modifiying variables that only differ in the index -


this question has answer here:

i programming right , wanted modify value of ten variables shared name had different index @ end. example:

    int number1     int number2     int number3     int number4     ... 

if want put same value in variables, example initialize them @ 0, there way loop in have modify index?

something this:

    for(int i=0;i<=10;i++) {        number"i" = 0; } 

probably silly question, can't find solution. thank :)

as mentioned in comment, go array.

from loop given in question, seems if want 10 numbers. in case like

int[] arnum = new int[10]; 

should declare array.

to initialize array 0, try

for (int = 0; < 10; i++)     arnum[i] = 0; 

note: array indexes start @ 0.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

android - Keyboard hides my half of edit-text and button below it even in scroll view -