- #1
MathematicalPhysicist
Gold Member
- 4,699
- 371
I have the following code
And then I get this annoying error in the terminal, that says the following:
How would you fix this error?
Thanks!
Java:
public class Assignment1 {
public static void main(String[] args) {
int x= Integer.parseInt(args[0]);
int y= Integer.parseInt(args[1]);
int z= Integer.parseInt(args[2]);
if (x<0 || y<0 || z<0) {
System.out.println("Invalid input!");
}
else {
if(x*x+y*y==z*z) {
System.out.println("The input ("+x+","+y+","+z+") defines a valid triangle!");
}
else {
System.out.println("The input ("+x+","+y+","+z+") does not define a valid triangle!");
}
}
}
}
So it seems the error is at line 4, i.eException in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at Assignment1.main(Assignment1.java:4)
int x = Integer.parseInt(args[0]);
How would you fix this error?
Thanks!