Hey guys i was having some trouble compiling/running some simple java code on my mac and i was wondering if you guys could help me out. This is very simple code to get me started with java, but whenver i run it i get this output:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at factorial.main(factorial.java:13)
java has exited with status 1.
i really dont know what to do with the code or anything. Any help will be greatly appreciated. Here's the code.
import java.util.*;
public class factorial {
public static void main(String[] args) {
int input = Integer.parseInt(args[0]);
double result = factorial(input);
System.out.println(result);
}
public static double factorial(int x) {
if (x < 0)
return 0.0;
double fact = 1.0;
while(x > 1) {
fact = fact * x;
x = x - 1;
}
return fact;
}
}
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at factorial.main(factorial.java:13)
java has exited with status 1.
i really dont know what to do with the code or anything. Any help will be greatly appreciated. Here's the code.
import java.util.*;
public class factorial {
public static void main(String[] args) {
int input = Integer.parseInt(args[0]);
double result = factorial(input);
System.out.println(result);
}
public static double factorial(int x) {
if (x < 0)
return 0.0;
double fact = 1.0;
while(x > 1) {
fact = fact * x;
x = x - 1;
}
return fact;
}
}