Hi I want to be able to find out the int (or float) value of a variable whoose name is in another string variable
int x = 10;
String var = "x";
System.out.println(Integer.valueOf(var).intValue());
I want 10 to be printed but all I get is :
Exception in thread "main" java.lang.NumberFormatException: For input string: "x"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:447)
at java.lang.Integer.valueOf(Integer.java:553)
at Line2f.main(Line2f.java:57)
Can you help me?