我懂了
线程“主”中的异常java.lang.ArrayIndexOutOfBoundsException:在RecursiveSquares.main(RecursiveSquares.java:40)处,索引0超出长度0的范围
public static void draw(int n, double x, double y, double size) {
if (n == 0) return;
drawSquare( x, y, size);
// 2.2 ratio looks good
double ratio = 2.2;
// recursively draw 4 smaller trees of order n-1
draw(n-1, x - size/2, y - size/2, size/ratio); // lower left
draw(n-1, x - size/2, y + size/2, size/ratio); // upper left
draw(n-1, x + size/2, y - size/2, size/ratio); // lower right
draw(n-1, x + size/2, y + size/2, size/ratio); // upper right
}
// read in an integer command-line argument n and plot an order n recursive
// squares pattern
public static void main(String[] args) {
int n = Integer.parseInt(args[0]);
double x = 0.5, y = 0.5; // center of square
double size = 0.5; // side length of square
draw(n, x, y, size);
您应该args
在执行程序时传递array 的值。例如。
java RecursiveSquares 10
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句