import com.bruceeckel.simpletest.*;
import java.util.*;
public class ArrayClassObj {
static Test monitor = new Test();
static Random rand = new Random();
public static void main(String[] args) {
Integer[] a = new Integer[rand.nextInt(20)];
System.out.println( "length of a = " + a.length);
for(int i = 0; i < a.length; i++) {
a[i] = new Integer(rand.nextInt(500));
System.out.println( "a[ " + i + "] = " + a[i]);
}
monitor.expect(new Object[] {
"%% length of a = \\d+ ",
new TestExpression( "%% a\\[\\d+\\] = \\d+ ", a.length)
});
}
} ///:~
问题:
Integer[] a = new Integer[rand.nextInt(20)];和 a[i] = new Integer(rand.nextInt(500));怎样解析?
后者a[i]为什么不是=integer[]?
------解决方案--------------------
Integer[] a = new Integer[rand.nextInt(20)];
定义一个长度不超过20的随机长度数组;
a[i] = new Integer(rand.nextInt(500));
对数组a的元素赋不超过500的随机值.
------解决方案--------------------
可以结了