为什么我从主类中收到index = 0和lenght = 0的错误?

尼尔森·尼尔森:

我懂了

线程“主”中的异常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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

为什么在此Javascript代码中不会将“ 0”和“未定义”视为错误?

为什么我收到KeyError:0

如果[0] == 0和0 == [[0]]都为真,那么为什么[0] == [[0]]为假?

sh中的“ $ {0%/ *}”和“ $ {0 ## * /}”

为什么calc(50%+ 0)错误?

0:0:0中的运行时错误错误,原因是:没有StatusBar提供程序

为什么0除以0在VBA中引发溢出错误?

错误:[filter:notarray]预期的数组,但收到:0

错误::0:0中的错误是由于:预期功能

为什么会收到错误:长度为0的参数

.BAT文件中的%0错误

为什么我的碰撞测试总是返回'true',为什么图像矩形的位置总是错误(0,0)?

为什么我的React单元测试中不断出现“接收的呼叫数:0”错误?

为什么会收到“被调用对象0不是函数错误”的信息?

为什么我收到MockMvc和JUnit的错误403?

Fortran“错误:不兼容分配中的等级0和1”

为什么当我在php中广告0 + 0时,我收到未定义的变量?

我使用 netbeans IDE,当我使用 Integer.parseInt(args[0]) 时,我收到了 ArrayIndexOutOfBoundsException。为什么?如何解决此错误?

为什么我在 1:nrow(counts) 中收到错误:长度为 0 的参数

为什么我会收到任何 Java 代码的“错误:无法找到或加载主类”?

为什么会出现错误“ArrayIndexOutOfBoundsException: length=0; index=0”?

“收到未知参数:0”条纹 Api 错误

为什么我会收到此错误:CSE 类没有名为 EnterRN 和 EnterName 的成员?

为什么我不断收到 ValueError:解决:输入操作数 1 在其核心维度 0 中不匹配?

为什么我会在 Fortran 中收到诸如 Unclassifiable statement at 1 和意外垃圾等错误?

在python中处理除以0错误和nan问题

'index 0 is out of bounds for axis 0 with size 0'是什么意思,我该如何解决这个错误?

为什么我在 Java 中收到“找不到类”错误?

为什么我收到此错误“图层“dense_30”的输入 0 与图层不兼容:预期 min_ndim=2,发现 ndim=1。收到完整形状:(无,)”