import java.util.Scanner; /* Java class that includes a method that, given a positive integer, prints ** its prime factorization. ** A main method is included for testing purposes. */ public class PrimeFactorize_F22 { /* Prints the prime factorization of the given integer, which is assumed ** to be positive. For example, in response to 3900, what will be printed ** is 2 2 3 5 5 13 */ public static void printFactors(int n) { int candFactor = 2; // candidate while ( n != 1 ) { if (n % candFactor == 0) { // candFactor divides into n System.out.print(candFactor + " "); n = n / candFactor; } else { candFactor = candFactor + 1; // } } System.out.println(); } public static void main(String[] args) { System.out.println("Welcome to the Prime Factorization program."); Scanner input = new Scanner(System.in); boolean keepGoing = true; while (keepGoing) { System.out.print("\nEnter an integer (negative to quit): "); int number = input.nextInt(); if (number <= 0) { keepGoing = false; } else { printFactors(number); } } System.out.println("Goodbye."); } }