perfect number

Write a program to check a number is perfect or not.

 

import java.util.*; class Perfact_no { public static void main() { int x,sum=0; System.out.println("Enter an integer \n\n"); Scanner in=new Scanner(System.in); x=in.nextInt(); for(int i=1; x>i;i++) { if(x%i==0) sum= sum +i; } if(sum==x) System.out.println(" It is a perfect number "); else System.out.println(" It is not a perfect number "); } }



For any desired program, please comment below. We will try our best to make that program available.


Comments

Popular Posts