Question: decompose a positive integer into a prime factor. For example, enter 90 and print 90 = 2*3*3*5.
ProgramAnalysis: to decompose the prime factor of N, first find a minimum prime number k, and then follow the steps below:
(1) If the prime number is equal to N, it indicates that the process of decomposing the prime factor is over. Print it out.
(2) If n <> K, but N can be divisible by K, the value of K should be printed, and N is divided by the quotient of K, as the new positive integer you, repeat the first step.
(3) If n cannot be divisible by K, k + 1 is used as the value of K and the first step is repeated.
Package WZS. arithmetics; // question: decompose a positive integer into a prime factor. For example, enter 90 and print 90 = 2*3*3*5. // Program analysis: to decompose the prime factor of N, first find a minimum prime number k, and then follow the steps below: // (1) if the prime number is equal to N, it indicates that the process of decomposing the prime factor has been completed. Print it out. // (2) if n <> K, but N can be divisible by K, the value of K should be printed and divided by the operator of n k as the new positive integer you, repeat the first step. // (3) if n cannot be divisible by K, k + 1 is used as the value of K and the first step is repeated. Public class test_wzs4 {public static void main (string [] ARGs) {test_wzs4.f (90 );} /*** decomposition prime factor * @ Param N */public static void F (INT number) {If (number <= 0) {system. out. println ("enter a positive number. "); Return ;}for (INT I = 2; I <number/2; I ++) {If (Number % I = 0) {system. out. print (I + "*"); F (number/I) ;}} system. out. println (number); // print the last prime factor system. exit (0); // exit the system. If this parameter is removed, an error occurs becauseCodeIs layer-by-layer inclusion, nested .}}