错误java.lang.ArrayIndexOutOfBoundsException? [重复]

问题描述 投票:-2回答:1

所以我试图创建一个n×n的三角形图案,但是每当我运行此文件时,它都会显示

线程“主”中的异常java.lang.ArrayIndexOutOfBoundsException:索引0超出长度0在qns1.Qns1.main(Qns1.java:12)

public static void main(String[] args) 
{ 
    int n = Integer.parseInt(args[0]);


    // loop n times, one for each row
    for (int i = 0; i < n; i++) {

        // print j periods
        for (int j = 0; j < i; j++)
            System.out.print(". ");

        // print n-i asterisks
        for (int j = 0; j < n-i; j++)
            System.out.print("* ");

        // print a new line
        System.out.println();

    }
}

任何帮助将不胜感激。非常感谢:D

java visual-studio-code indexoutofboundsexception
1个回答
0
投票
java <filename>.java "6"
© www.soinside.com 2019 - 2024. All rights reserved.