Wednesday, January 28, 2015

Factors.java in progrme...



Factors.java

public class Factors 
{
public static void main(String[] args) 
{ 
                     long n = Long.parseLong(args[0]);
                     System.out.print("The prime factorization of " + n + " is: ");
 
         for (long i = 2; i*i <= n; i++)
         {
                       while (n % i == 0) 
         {
                System.out.print(i + " "); 
                n = n / i;
            }
        }
                      if (n > 1) 
                          System.out.println(n);
        else       
          System.out.println();
    }
}

No comments:

Post a Comment