For a given integer n > 1, the smallest integer d > 1 that divides n is a prime factor. We can find the prime factorization of n if we find d and then replace n by the quotient of n divided by d, repeating this until n becomes 1. Write a java program that uses a stack to print the prime factors of a positive integer in descending order. For example, for n = 3960, your program should produce 11*5*3*3*2*2*2.

A stack can be used to print numbers in other bases (multibase output). Examples:

  • (Base8) 28 base 10 = (3 * 8^1) + (4 * 8^0) = 34 base 8
  • (Base4) 72 base 10 = (1 * 4^3) + (0 * 4^2) + (2 * 4^1) + (0 * 4) = 1020 base 4
  • (Base 2) 53 base 10 = (1 * 2^5) + (1 * 2 ^ 4) + (0 * 2^3) + (1 * 2^2) + (0 * 2^1) + (1 * 2^0) = 110101 base 2

Write a java program using stacks that takes 3 non-negative (base 10) long integer numbers and a base B (B is in the range 2-9) end writes the number to the screen as a base B number. The program prompts the user for 3 numbers and bases, and then outputs them.

Use as input:

  • 72 base 10 to base 4
  • 53 base 10 to base 2
  • 3553 base 10 to base 8
Academic Honesty!
It is not our intention to break the school's academic policy. Projects posted are only used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly fill out the form. Please provide a valid email address and we'll get back to you in less than 24 hours. We will be sending an invoice through PayPal upon confirmation. We are a non profit organization however we need an amount to keep this organization running, and to be able to complete our research and development.