WHAT'S NEW?

Perfect Number Logic in Java

Perfect Number Logic In Java



class PerfectNumber 
{
public static void main(String[] args) 
{
int sum=0, num=28, i;
         for(i=1;i<num;i++)
         {
                 if(num%i==0)
                          sum=sum+i;
         }
         if(sum==num)
{
System.out.println(""+num+" is a PERFECT NUMBER");
}
         else
{
System.out.println(""+num+" is a not a PERFECT NUMBER");
}
}

}




Perfect Number is a number whose factors add up for the number itself.

suppose number is x and its factors are a,b,c.

Then x will be considered as Perfect number if.

a+b+c=x

factors of 28 are 1,2,4,7,14.

&

1+2+4+7+14 =28

Hence 28 is a Perfect Number


1 comment: Leave Your Comments

  1. Whether or not firms will successfully bridge these two fields is yet to be seen. Casinos usually accept all bets made by patrons within a longtime limit, so that a patron can not win more than a on line casino can afford to pay. Every sport supplied provides a on line casino a mathematical expectancy of successful, and it is rather rare for a on line casino to lose money on its games, even for in the future. Even lesser bettors are supplied reduced-fare transportation, 온라인카지노 hotel rooms, free drinks and cigarettes whereas gambling, and different inducements. While traditional casinos have been in existence an extended time|for a very lengthy time}, the digital era has escalated the market leaders to a greater novelty. All that, nevertheless, has been achieved whereas maintaining the core of on line casino gaming intact.

    ReplyDelete