Showing posts with label perfect number. Show all posts
Showing posts with label perfect number. Show all posts

Sunday, June 21, 2020

Write a program to input a number and check whether it is Perfect Number or not?(6=factor=1,2,3 =1+2+3=6 , sum=number)

30)  Write a program to input a number and check whether it is Perfect Number or not?(6=factor=1,2,3 =1+2+3=6 , sum=number)

import java.util.*;
public class perfect_number
{
    public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter a number");
        int a = sc.nextInt();
        int c = 0;
        for(int i=1;i<a;i++)
        {
            if(a%i==0)
            c=c+i;
        }
        if(c==a)
        {
            System.out.println("Entered number is a PERFECT number");
        }
        else
        {
            System.out.println("Entered number is not a PERFECT number");
        }
    }
}

 jhvghvgk ;nkjn ,nkjhj