variable substitution
Hello, all
I am new to Java (and to this forum) but I do have a background in javascript. I am wondering if the following is possible in Java?
//////////////////////////////////////////////////
import static java.lang.System.out;
public class Demo
{
int num1, num2, num3;
public static void main (String [] args)
{
for (int i=1; i <= 3; i++)
{
num = i;
out.println(num);
{
}
}
/////////////////////////////////////////////
In this code, I want to be able to substitute the value of i in the for loop for the name of the variable, so that the first time through the loop the variable becomes num1 which gets a value of i and is printed, the 2nd time
through the loop it becomes num2 etc. I realize this is a simple example and could easily be done without this kind of substitution, but in other examples with more complicated code it would be useful.
I know this kind of variable substitution - I'm not even sure it's called variable substitution - can be done in javascript, but can it be done in java?
Thank you for any assistance.
nrdaddy

