Question

Write a Java application that asks for an integer

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;


public class factorialFactorization {

   /**
   * @param args
   */
   public static void main(String[] args) {
       // TODO Auto-generated method stub
       Scanner scan = new Scanner(System.in);
       System.out.print("Enter a number:");
       int n = scan.nextInt();
       int fact=1;
       for(int i=2;i<=n;i++)
       {
           fact = fact*i;
       }
       int count=0,hat=0;
       System.out.print(fact);
       System.out.print(" = ");
       for(int i=2;fact>1;i++)
       {
           count = 0;
           while(true)
           {
               if(fact%i==0)
               {
                   count++;
                   fact = fact/i;
               }
               else
               {
                   break;  
               }
           }
          
           if(count>0)
           {
               if(hat>0)
               {
                   System.out.print(" * ");
               }
               System.out.print(i);
               System.out.print("^");
               System.out.print(count);
               hat ++;
           }
       }
   }

}

Add a comment
Know the answer?
Add Answer to:
Write a Java application that asks for an integer and returns its factorization into prime factors...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT