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
  • The prime factorization of a number is the unique list of prime numbers that, when multiplied,...

    The prime factorization of a number is the unique list of prime numbers that, when multiplied, gives the number. For example, the prime factorization of 60 is 2 ∗ 2 ∗ 3 ∗ 5. In this problem you must write code to recursively find and return the prime factorization of the given number. You must print these in ascending sorted order with spaces in between. For example, if your input is: 120 then you should print the following output: 2...

  • The prime factorization of a number is the unique list of prime numbers that, when multiplied,...

    The prime factorization of a number is the unique list of prime numbers that, when multiplied, gives the number. For example, the prime factorization of 60 is 2 ∗ 2 ∗ 3 ∗ 5. In this problem you must write code to recursively find and return the prime factorization of the given number. You must print these in ascending sorted order with spaces in between. For example, if your input is: 120 then you should print the following output: 2...

  • For a given integer n > 1, output its prime factorization. (Please follow the format strictly)...

    For a given integer n > 1, output its prime factorization. (Please follow the format strictly) Example: n=8, output: 2^3 n=72, output: 2^3*3^2. (2^3 means 23) In Java please

  • In R! Write a function named prime_factor(x) that will find the prime factorization of an integer...

    In R! Write a function named prime_factor(x) that will find the prime factorization of an integer x. The function will output a numeric vector. All of the values in the output vector will be prime. The product of the numeric vector will be the original value x. There should be a check to make sure that the input value is a number greater than 2 with no decimal values with appropriate error messages. If you’re stuck on getting started with...

  • In Java, write a program that uses a stack to print the prime factors of a...

    In Java, write a program that uses a stack to print the prime factors of a positive integer in descending order.

  • We use JAVA. Thanks.    Create an application whose main method asks the user to enter...

    We use JAVA. Thanks.    Create an application whose main method asks the user to enter an n by m integer matrix that contains nm integer numbers. n and m should be between 1 and 10. If the user enters a             number less than 1 or greater than 10, the program will continue to ask the user to enter an integer number between 1 and 10. The program should print the sum of the boundary elements of the matrix....

  • Write a java program that asks the user to enter an integer. The program should then...

    Write a java program that asks the user to enter an integer. The program should then print all squares less than the number entered by the user. For example, if the user enters 120, the program should display 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, and 100.

  • Write a Java Program to find the sum of all factors of a given positive integer....

    Write a Java Program to find the sum of all factors of a given positive integer. Make sure to satisfy and show different results for any inputs, for example, 0, negative numbers, odd numbers, prime numbers, huge integers, etc. For example, if the integer is 12: Then the factors are: 1, 2, 3, 4, 6, 12 ; And their sum is: 28.

  • Java Q6 Part 6 Write a program with the class name BoxMaker that asks the user...

    Java Q6 Part 6 Write a program with the class name BoxMaker that asks the user for an integer x (using Scanner), and then builds a box ofx asterisks. For example, if x = 4, then your output would be: // inner body " ": x - numLids ("*" on each side) == x - 2

  • Using java Sample Outputs Write a program which asks the user for an integer and then...

    Using java Sample Outputs Write a program which asks the user for an integer and then prints the following patterns based on that integer. Input Validation For Pattern 1, the input must be a value between 1 and 999 For Pattern 2, the input must be a value between 1 and 26. Requirements: For Pattern 1: must be able to work with up to three digit numbers. You will want to use printf to get the spacing correct. For Pattern...

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