"Index 0 out of bounds for length 0" error message.
I'm new to coding. Trying to teach myself with a college textbook that utilizes Java to teach a course in computer science. I downloaded the Intellij IDE because it has certain applications that will show you the errors in your code. I attempted an exercise to learn how to program Quadratic formulas, but keep getting an error message when I run the program that reads: "Index 0 out of bounds for length 0." I clicked on the Java 5 icon in the error message and it moves the cursor up to the 1st 0 of the 1st line of code, but beyond that I am at a loss as to how to fix the error. I got the same error message earlier when I attempted to program a program for integer multiplication and division. Is there something I am missing that would make the program run correctly?
The textbook I am using is Computer Science: An Interdisciplinary Approach by Robert Sedgewick and Kevin Wayne. The program I entered was as follows:
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 d = Math.sqrt(discriminant);
System.out.println((-b + d) / 2.0);
System.out.println(((-b - d) / 2.0));
}
}
Please sign in to leave a comment.
You need to send arguments to the program, as you are using them: https://i.imgur.com/PUKaIRO.png