Question: decompose a positive integer into a prime factor. For example, enter 90 and print 90 = 2*3*3*5.
Program Analysis: to break down 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 n, 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.
Import java. util .*;
Public class lianxi04 {
Public static void main (string [] ARGs ){
S = new partition (system. In );
System. Out. Print ("enter a positive integer :");
Int n = S. nextint ();
Int K = 2;
System. Out. Print (n + "= ");
While (k <= N ){
If (k = N ){
System. Out. println (n); break;
}
Else if (N % K = 0 ){
System. Out. Print (K + "*"); n = N/K;
}
Else K ++;
}
}
}
Http://my.csdn.net/se_xiaofeng welcome to my blog!