I recently made a post saying that my code wasn't working and displayed the message:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at FactorialProgram5.main(FactorialProgram5.java:11)
with the code:
import java.util.Scanner;
public class FactorialProgram5 {
public static void main(String args[]) {
long n;
long fact = 1;
n = 1;
for (int i = 1; i <= n; i++) {
n = Long.parseLong(args[0]);
fact = fact * i;
}
System.out.print("fact=" + fact);
}
}
Someone said I have to pass arguments to it and that the array is empty. What does it mean to pass an argument to the code? I am using eclipse, and someone told me that I have to go to the arguments tab and enter a value manually, but I need to make it so I can use this code in the command prompt too. How can I do this?