Páginas

terça-feira, 21 de maio de 2019

public static and return

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package fatorial;

import java.util.Scanner;

/**
 *
 * @author aluno
 */
public class Fatorial {
   
    public static int fatorial(int numero){
        int fato = 1;
        for(int i = 1; i <= numero ; i++){
            fato *= i;
        }
        return fato;
    }
   

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner teclado = new Scanner (System.in);
        System.out.println("Informe um numero:  ");
        int n = teclado.nextInt();
     
       
        //int fato = fatorial(n);
        System.out.println("O fatorial de "+ n + " é = "+fatorial(n));
     
    }
   
}

Sem comentários:

Enviar um comentário