Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pila;
- import java.util.Stack;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- int suma=0,num;
- Scanner lectura= new Scanner(System.in);
- Stack<Integer> pilaP=new Stack<Integer>();
- do {
- System.out.println("Ingrese un numero positivo:");
- num=lectura.nextInt();
- }while (num<=0);
- for (int i=1;i<num;i++){
- if (num%i==0) {
- pilaP.push(i);
- suma+=pilaP.pop();
- }
- }
- if (suma==num){
- System.out.println("El numero ingresado es perfecto");
- }else {
- System.out.println("El numero ingresado no es perfecto");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement