Proxy > Gmail Facebook Yahoo!

16. Using the definition of perfect number, find all the perfect numbers in a range of numbers.



import java.util.*;

public class PerfactNumber
{
  public static void main(String [] args)
  {
    Scanner scan=new Scanner(System.in);
    System.out.println("Enter Starting Range:");
    int startRange=scan.nextInt();
    System.out.println("Enter Ending Range:");
    int endRange=scan.nextInt();
   
    System.out.print("Perfact Number between Range=:");
    for(int num=startRange;num<=endRange;num++)
    {
      int temp=0;
      for(int i=1;i<num;i++)
      {
        if(num%i==0)
        {
          temp=temp+i;
        }
      }
      if(temp==num)
      {
        System.out.print(num+", ");
      }
    }
  }                                       
}


Responses

0 Respones to "16. Using the definition of perfect number, find all the perfect numbers in a range of numbers."


Send mail to your Friends.  

Expert Feed

 
Return to top of page Copyright © 2011 | My Code Logic Designed by Suneel Kumar