PERFECT NUMBER in Java. ( WITH DO WHILE)
************************************
import java.util.Scanner;
class PerfectNumber
{
public static void main (String arts[])
{
int sum =0;
int i=1;
Scanner sc=new Scanner(System.in);
System. out.println("Enter a Number");
int num=sc.nextInt();
do
{
if(num%i=0)
sum=sum+i;
i++;
}
while(i <= num/2)
if(sum == num)
System.out.println(num+ "is a PERFECT NUMBER");
else
System.out.println(num+ "is NOT a PERFECT NUMBER");
}
}
*********************************
0 Comments