I'd like to assign a set of variables in java as follows:
int n1,n2,n3;
for(int i=1;i<4;i++)
{
n<i> = 5;
}
How can I achieve this in Java?
I'd like to assign a set of variables in java as follows:
int n1,n2,n3;
for(int i=1;i<4;i++)
{
n<i> = 5;
}
How can I achieve this in Java?
If you want to access the variables some sort of dynamic you may use reflection. However Reflection works not for local variables. It is only applyable for class attributes.
A rough quick and dirty example is this:
You need to improve this code in various ways it is only an example. This is also not considered to be good code.