Como fazer fatorial com while?

Como?

Ola @Pixels15,

conhece o Guava?

tem método para calcular o fatorial, ex:

BigInteger fatorial = BigIntegerMath.factorial(new BigInteger("12").intValue());

Library : Guava
Jar File: guava-19.0.jar

Mas queria o método mais simples usando while…

while é apenas uma estrutura de repetição, não esta associado ao cálculo.

import javax.swing.JOptionPane;

public class FatorialWhile {
public static void main(String[] args) {
	int intcontador = 1, fat, valor;
	valor = Integer.parseInt(JOptionPane.showInputDialog(null,"Entre numero", "entrada", JOptionPane.INFORMATION_MESSAGE));
	fat = 1;
	String result = "o fatorial de " + valor + " é :";
	while (intcontador <= valor) {
		fat = fat + (fat * (valor - 1) );
		valor--;
	}
	JOptionPane.showMessageDialog(null, result + fat, "Resultado", JOptionPane.INFORMATION_MESSAGE);
}
}

Origem: Fatorial while "help".[Resolvido]

2 curtidas

legal, mas fatorial acima de 12 ele se perde e acima da resultado 0 precisa ajustar dependendo da utilização.

Olá,

algoritmo:

fat=1
n=5
while(n > 1) {
   fat = fat*n;
   n--;
}
imprime fat

Isso é muito trivial, tente escrever o algoritmo primeiro, como fiz, para então tentar a implementação.