java - Modifiying variables that only differ in the index -
this question has answer here:
- dynamic variable names java 3 answers
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
Post a Comment