Title: Decompose a positive integer into factorization. For example: Enter 90 and print out 90=2*3*3*5.
Program Analysis: The decomposition of n factorization, should first find a minimum prime number k, and then the following steps to complete:
(1) If the prime number is exactly equal to N, then the process of decomposing the factorization is finished and printed out.
(2) if n<>k, but n can be divisible by K, the value of k should be printed, and n divided by the quotient of K, as a new positive integer n, repeat the first step.
(3) If n cannot be divisible by K, the first step is repeated with k+1 as the value of K.
Public classTest1 { Public voidZhiintN) {System.out.print (n+"="); for(inti=2;i<=n;i++){ while(N%i==0 && n!=i) {N/=i; System.out.print (i+"*"); } if(n==i) {System.out.println (i); Break; } } } Public Static voidMain (string[] args) {Test1 test=NewTest1 (); Test.zhi (20); }}
Java Practice (iv)--decomposition factorization