有一个随机数,我想生成这个随机数变量,该怎么做?比如:产生8,我要生成一个变量名为8的变量该怎么做?
不要这样产生变量,会消耗内存,请用数组,会很方便
int randnum[]= new int[100];
for(int i;i<100;i++){
randnum[i]=i;
}
你该不会是想动态定义变量吧?!
应该是不行的
呵呵,这好像不能实现的,你可以这样作:
扩展或使用java.util包中的map,来实现“键-值”对,添加某键为“8”,想获取与其对应的值时,map.getObject("8")即可。
too naive***
the variable name is meaningless for compiler and end users. Its only for the convenience of your reading codes.
So you dont need to assign such a "meaningful" name to it.
and its not reasonable.