您的位置:首页 > 其它

虚拟化--搭建VCAC手册

2015-08-23 09:15 253 查看
//对非primitive对象数组操作时,初始化要注意
import java.util.*;

class ArrayClassobj {
static Random rand = new Random();
static int pRand(int mod) {
return Math.abs(rand.nextInt())%mod +1;
}

public static void main(String [] args) {
Integer [] a = new Integer[pRand(30)];
prt("length of a = " + a.length);

for(int i = 0 ; i < a.length ; i ++){
//如果没有这行代码,数组初始化将没有完成,只是初始化了一个数组句柄
a[i] = new Integer(pRand(500));
prt("a[" + i + "] = " + a[i]);
}
}

static void prt(String s) {
System.out.println(s);
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: