Hello! This is my first post and I am a beginner in Java programming-so don't come down on me too hard :) I have a problem that I need to solve over the weekend and I was hoping some of you could help me out. The problem at hand is that I need to compute n! where n is an integer entered by the user. the catch is that I need to store the answer in an array (up to 50 places) and print back the array such like (12! = ) 479001600 and being able to omit all leading zeros from the printout. I know I need to divide by 10 and mod by 10 to get the remainder so I can store the value in the next element of the array, but I don't know how. Our teacher told us to go ahead and load the array with zeroes and initialize the last element (x.length - 1) to 1 because 0! and 1! are 1 so that made sense to me, and I believe I have the code correct to compute the factorial, I just need some ideas/help as to storing those values in the array and printing that array...so here goes
import java.util.*;
public class Prog3
{
public static void main(String[] args)
{
double n;
double factorial = 1;
Scanner input = new Scanner(System.in);
System.out.println("Enter a non-negative integer and I will compute its factorial");
n = input.nextDouble();
while (n<0)
{
System.out.println("Please enter a NON-negative number!");
n = input.nextDouble();
}
while (n >0)
{
factorial = factorial * n;
n--;
}
int[] x = new int[50];
for(int i = 0; i <x.length; i++)
x[i] = 0;
x[x.length - 1] = 1;
for(int
}
}
*EDIT* of course I wrote computer in the title instead of *compute* sorry!