ArrayIndexOutOfBounds exception in main method

后端 未结 4 1246
不思量自难忘°
不思量自难忘° 2021-01-25 18:53

I am getting array bound error but to my mind, array starts from 0, so what is wrong with this code?

public class Quadratic {

    public static void main(String         


        
4条回答
  •  执念已碎
    2021-01-25 19:15

    You don't have an item in args[0] and/or args[1]. You need to check that there are enough arguments in the array.

    double b = args.length>=1?Double.parseDouble(args[0]):0.0;
    double c = args.length>=2?Double.parseDouble(args[1]):0.0;
    

    If there are no arguments in the array, then it means that you didn't pass an argument into the program or you didn't pass enough arguments.

提交回复
热议问题