Advertisement
FacuValverdi

EDTP02.-Ejercicio3

Sep 19th, 2019
394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.62 KB | None | 0 0
  1. package pila;
  2. import java.util.Stack;
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.     public static void main(String[] args) {
  7.         int suma=0,num;
  8.         Scanner lectura= new Scanner(System.in);
  9.         Stack<Integer> pilaP=new Stack<Integer>();
  10.         do {
  11.             System.out.println("Ingrese un numero positivo:");
  12.             num=lectura.nextInt();
  13.         }while (num<=0);
  14.             for (int i=1;i<num;i++){
  15.                 if (num%i==0) {
  16.                     pilaP.push(i);
  17.                     suma+=pilaP.pop();
  18.                 }
  19.             }
  20.             if (suma==num){
  21.                 System.out.println("El numero ingresado es perfecto");
  22.             }else {
  23.                 System.out.println("El numero ingresado no es perfecto");
  24.             }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement