Tuesday , January 24 2017
Home / java programs / Java Program to Check the Number is Perfect or not ?

Java Program to Check the Number is Perfect or not ?

Here we are going to write a program to check a number is Perfect or not ?

Number is Perfect or not ?


import java.util.Scanner;

public class IsPerfectNumber {

    public static void main(String a[]) {

        int tempValue = 0;
        Scanner s1 = new Scanner(System.in);
        System.out.println("Enter a Number");
        int inputValue = s1.nextInt();

        for (int count = 1; count <= inputValue / 2; count++) {
            if (inputValue % count == 0) {
                tempValue = tempValue + count;
            }
        }

        if (tempValue == inputValue) {
            System.out.println("Given Number is a perfect number");
        } else {
            System.out.println("Given Number is Not a perfect number");
        }

    }
}

Output :

Enter a Number 28
Given Number is a perfect number

Enter a Number 20
Given Number is Not a perfect number

About chandrashekhar

Hi Folks, you have reach this so far, that shows you like what you are learning. Then why don't you support us to improve for bettor tutorials by leaving your valuable comments and why not you keep in touch with us for latest updates on your favorite blog @ facebook , twitter , Or Google+ ,

Check Also

Java Program To find A Number is ArmStrong or Not ?

Here we are going to write a program to check a number is ArmStrong or …

Leave a Reply

Your email address will not be published. Required fields are marked *