Ola,
Esse é um exemplo de programa q tem num livro que estou vendo
O programa compilo mas na hora de colocar o valor dah ‘ArrayIndexOutOfBonds’,o q significa isso?
mas isso nao eh minha maior preocupação,tipo… eu to venu 2 programas iguais ae embaixo
o que tah no public static void main e o outro metodo factorial que funciona normal sem o public static void main,
porque a necessidade desses dois metodos juntos?
public class Factorial { // Define a class
public static void main(String[] args) { // The program starts here
int input = Integer.parseInt(args[0]); // Get the user's input
double result = factorial(input); // Compute the factorial
System.out.println(result); // Print out the result
} // The main() method ends here
public static double factorial(int x) { // This method computes x!
if (x < 0) // Check for bad input
return 0.0; // If bad, return 0
double fact = 1.0; // Begin with an initial value
while(x > 1) { // Loop until x equals 1
fact = fact * x; // Multiply by x each time
x = x - 1; // And then decrement x
} // Jump back to start of loop
return fact; // Return the result
} // factorial() ends here
} // The class ends here
Vlew