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

HALLAR LA DISTANCIA DE LOS PUNTOS


Clase Principal

package packDistancia;
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 x1");
     int a1  = Integer.parseInt(Teclado.readLine());
       System.out.println("ingrese x2");
     int a2  = Integer.parseInt(Teclado.readLine());
       System.out.println("ingrese y1");
     int b1  = Integer.parseInt(Teclado.readLine());
       System.out.println("ingrese y2");
     int b2  = Integer.parseInt(Teclado.readLine());
       
        Puntos objpunto = new Puntos(a1,a2,b1,b2);
       
        double res=objpunto.Generar(a1,a2,b1,b2);
       
        System.out.println(res);
       
                      
           }
}










 Clase Puntos


package packDistancia;

public class Puntos {
   
    private  int x1;
    private  int x2;
    private  int y1;
    private  int y2;

    public Puntos(int x1, int x2, int y1, int y2) {
        this.x1 = x1;
        this.x2 = x2;
        this.y1 = y1;
        this.y2 = y2;
    }
   
    public double Generar(int x1, int x2, int y1, int y2){
   
        double r;
        r=Math.sqrt(Math.pow((this.x2-this.x1),2)+Math.pow((this.y2-this.y1),2));
         return r;  }
     
   
}



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

NUMEROS ALEATORIOS


Clase Principal


package packaleatorio;

import java.util.Random;


public class principal {


    public static void main(String[] args) {
      
        Random rnd =new Random();
        Aleatorio viernes = new Aleatorio();
        for(int i=1; i<=10; i++)
        {
        int num = rnd.nextInt(30);
        viernes.setValor(num);
        if(viernes.VerificarSiNoPrimo())

             System.out.println("es un numero primo:  " + num);
        else
             System.out.println("no es numero primo:  " + num);

       
        }}}




Clase Aleatoria


package packaleatorio;

public class Aleatorio {
private int valor;

public Aleatorio(){

           this.valor=0;
}

    public void setValor(int valor) {
        this.valor = valor;
    }
public boolean VerificarSiNoPrimo()
{
    int cont=0;
    for (int p=1; p<=this.valor; p++)
    {

        if (this.valor % p ==0)
            cont++;
    }
    if (cont<=2)
        return true;
    else
        return false;
}}

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

CLASE SUMADOR


Clase Principal


package pckSumador;

import java.io.*;

public class Principal {
    //Objetos Leer Datos Teclado.
    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.print("Ingrese valor 1: ");
        int valor1 = Integer.parseInt(Teclado.readLine());

        System.out.print("Ingrese valor 2: ");
        int valor2 = Integer.parseInt(Teclado.readLine());

        Sumador Obj1 = new Sumador(valor1,valor2);

        int resul = Obj1.GenerarSuma();

        System.out.println("Resulltado = " + resul);
       
    }}



Clase Sumador


package pckSumador;

public class Sumador {

    //Atributos-variables de instancia.
    private int num1;
    private int num2;

   //Metodos (Constructor - Convencional).
    public Sumador(int num1, int num2)
    {
        this.num1 = num1;
        this.num2 = num2;
    }

    public Sumador()
    {
        this.num1=0;
        this.num2=0;
    }
    public int GenerarSuma()
    {
       int sum=this.num1 + this.num2;
       return sum;
    }
}

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