* Title: Decompose a positive integer into factorization. For example: Enter 90 and print out 90=2*3*3*5.
* Analysis: To decompose n factorization, you should first find a minimum prime number k, and then complete the following steps:
* (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 you 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.
* This topic is obviously to use recursive algorithm to achieve, print "*" some skills, but also easy to solve, the program is as follows:
import java.util.scanner;public class yinshifenjie { public Static void fenjie (int n) { for (int i=2;i <=n;i++) { if (i == n) { system.out.print (i); return; } if (n > i && (n % i == 0) { system.out.print (i+ "*"); fenjie (N / i); break; } } } public static void main (String[] args) { scanner input = new scanner (system.in); system.out.println ("Please enter an integer:"); int n = input.nextint (); fenjie (n); }}
This article is from the "Orange Growth Record" blog, be sure to keep this source http://azhome.blog.51cto.com/9306775/1547229
The Java implementation decomposes a positive integer factorization