lunes, 21 de marzo de 2011

Factorial de un Numero

Logica ---> Factorial.
Presentacion ---> Formulario.

Descarga... click acá
Logica --->Factorial
  •  /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */

    package Logica;

    /**
     *
     * @author MAURICIO
     */
    public class Factorial {

        private
            int num1;

        public int getNum1() {
            return num1;
        }

        public void setNum1(int num1) {
            this.num1 = num1;
        }

        public Factorial(int num1) {
            this.num1 = num1;
        }

        public int Factorial(int numero){
        int resultado = 1;
        for(int i = 1 ;i <= numero; i++)
        {
            //System.out.println(i);
            resultado = resultado * i;
        }
        return (resultado);
        }
    }
Presentacion --->Formulario
  • /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */

    package Presentacion;
    import Logica.Factorial;
    /**
     *
     * @author microsoft
     */
    public class Formulario {

        public static void main(String arg[])
        {
            Factorial obj1 = new Factorial(5);
            System.out.println("El factorial de " +obj1.getNum1() + " es " + obj1.Factorial(obj1.getNum1()));

        }
    }

No hay comentarios:

Publicar un comentario