SHARE
TWEET

EDTP02.-Ejercicio3

FacuValverdi Sep 19th, 2019 114 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top