Java返回:1

时间:2018-01-08 11:14:58

标签: java

class Compound {

    public static void main(String args[]) {
        int P = Integer.parseInt(args[0]);
        int R = Integer.parseInt(args[1]);
        int T = Integer.parseInt(args[2]);
        int Ci, i, A = 1, Pa = P;
        for (i = 1; i <= T; i++) {
            Ci = P * R / 100;
            P = P + Ci;
            A = P + Ci;
        }
        Ci = A - Pa;
        System.out.println(Ci + " is the Ci\nAmount=" + A);
        return 1;
    }
}

抛出以下异常:

  

线程中的异常&#34; main&#34; java.lang.ArrayIndexOutOfBoundsException:0           在Compound.main(JavaApplication1.java:3)       C:\ Users \ Dell \ AppData \ Local \ NetBeans \ Cache \ 8.2 \ executor-snippets \ run.xml:53:Java返回:1       BUILD FAILED(总时间:2秒)

这是发生了什么请告诉错误的原因和合适的代码来避免它。以上是复利的简单程序

1 个答案:

答案 0 :(得分:0)

你的程序崩溃了,因为你在没有3个参数的情况下调用它而只是假设它们在那里。

在处理之前,您需要确保实际上拥有所有三个参数。将@Startup @Singleton public class StartupBean { @PostConstruct void postConstruct { //your code } ... } 中的代码现在放在一个函数中,并在有3个args时调用它。

main