ArrayIndexOutOfBounds exception in main method

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[] args) {
        double b = Double.parseDouble(args[0]);
        double c = Double.parseDouble(args[1]);

        double discriminant = b*b - 4.0*c;
        double sqroot = Math.sqrt(discriminant);

        double root1 = (-b + sqroot)/ 2.0;
        double root2 = (-b - sqroot)/ 2.0;

        System.out.println(root1);
        System.out.println(root2);
    }
}
Answer:1

Protect yourself: be defensive.

    public class Quadratic {

    public static void main(String[] args) {

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

            double discriminant = b*b - 4.0*c;
            double sqroot = Math.sqrt(discriminant);

            double root1 = (-b + sqroot)/ 2.0;
            double root2 = (-b - sqroot)/ 2.0;

            System.out.println(root1);
            System.out.println(root2);
        } else {
            System.out.println("two arguments are required: b and c, please");
        }
    }
}

What happens if the discriminant is negative? What if it's zero?

Why are you restricting yourself to the case where a = 1?

Answer:2

Try and debug it. print the size of args using System.out.println(args.length);. if the size is smaller then 2 your not getting the parameters to your main class.

Answer:3

I am using REST Assured, but when I try to send the request I am getting the below error:- javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed:...

I am writing a software test automation tool and I have a Journal Record Proc in a DLL. Now when the Proc gets called by Windows I want to call a method in a Java class from it. Is this possible ?

During my rules execution, I will be "inserting" new fact object in memory that I will need to read when the rules are done firing. How can I read those facts when outside the Rules Session? I have ...

Im using CursorAdapter in my Listview for direct mapping of data to the database. my problem is when im creating a drag and drop listview. How to drag and drop items in Listview for reordering in ...