First of all, variable names in Java can't begin with a number.
Quote
Basically all I want to know is if it is possible to use a variable as a variable definition
I never saw that happen in Java before. It is possible to get the value of a variable by just having the name, with reflection. But that's very ugly code.
For cases like yours, a Map is often used. Example:
import java.util.HashMap;
public class Test {
HashMap<Integer, Integer> intMap;
int[] intArray;
public Test() {
intMap = new HashMap<Integer, Integer>();
}
private void fillHashMap(){
for(int n=0; n<10 ; n++){
intMap.put(n, n*24);
}
}
private void createArray(){
intArray = new int[intMap.size()];
for(int i=0 ; i<intArray.length ; i++){
intArray[i] = intMap.get(i);
}
}
private void printArray(){
for(int number : intArray){
System.out.println(number);
}
}
public static void main(String[] args) {
Test test = new Test();
test.fillHashMap();
test.createArray();
test.printArray();
}
}
Quote
Oh by the way I'm aware I could do something like this probably easier using an array. I'm doing this because I don't know how many results I am going to need for int (n), where n is the predefined variable. until I have tested some data, then I need to be able to record the result to display in sequence later (where int (n)) is the data test results for display.
If the only reason you're doing this is that you don't know the size of the array up front then use a dynamic array. The most used collection type in Java is probably the ArrayList. There is no need to predefine the size of it, as it will automatically expand.
ArrayList myList = new ArrayList<Integer>();
myList.add(2);
myList.add(15);
myList.add(3);
for(int i=0 ; i<myList.size() ; i++){
System.out.print(myList.get(i) + " ");
}