Fatorial em Java
import java.util.Scanner;
import java.util.InputMismatchException;
 
public class fatorial    
{
 
    public static int fat(int a) {
            if(a == 0){
            return 1;
        }else{
                return a*fat(a-1);
        }
    }
 
    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("digite um número positivo para calcularmos o seu FATORIAL");
        int a = sc.nextInt();
        System.out.println(fat(a));
    }
}

voltar

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.