REALIZAR UN PROGRAMA QUE PERMITA AL USUARIO INGRESAR 10 Y ENCUENTRE LOS NUMEROS PERFECTOS

Clase Principal

package pckNumeroPerfecto;
import java.io.*;

public class Principal
{
    public static InputStreamReader Leer = new InputStreamReader(System.in);
    public static BufferedReader Teclado = new BufferedReader(Leer);
   
    public static void main(String[] args) throws IOException
    {
        System.out.println("Ingrese 10 Valores...!");

        int num=0,cont=0;
       
        Perfecto miercoles = new Perfecto();

        for(int i=1;i<=10;i++)
        {
          num = Integer.parseInt(Teclado.readLine());
          if(miercoles.VerificarPerfecto(num))
          {
            System.out.println("Numero Perfecto= " + num);
            cont++;
          }
        }
        System.out.println("Existen Numeros Perfectos: " + cont);

       
    }

}
 
Clase Perfecto


package pckNumeroPerfecto;

public class Perfecto {
    private int valor;

    public Perfecto()
    {
      this.valor=0;
    }
    public boolean VerificarPerfecto(int valor)
    {
        this.valor = valor;
        int sum=0,t=1;
        while(t<this.valor)
        {
          if(this.valor % t == 0)
              sum+=t;
          t++;
        }
        if(sum==this.valor)
            return true;
        else
            return false;
    }

}



  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • RSS

0 comentarios:

Publicar un comentario