0
I can’t find the error in my code. When I put numbers smaller or equal to 12 my program gives the right result, but from the number 13 the values come out wrong and I can not know why. What’s the mistake?
class vdois {
static int fatorial (int numero){
int fat = 1;
while (numero >0) {
fat *= numero;
numero--;
}
return fat;
}
public static void main(String[] args) {
int numero = 13;
System.out.println(numero+"! = "+fatorial(numero));
}
}
It’s not the same because I want to know what the mistake in the way I did.
– Juliana
Not exceeding the maximum value of
int
? Replaced byfloat
for you to see.– Woss
It worked! But instead of printar 62272... printou 6.2272..., has problem happen that?
– Juliana