1 Packagetest;2 3 ImportJava.util.Scanner;4 5 Public classTest19 {6 /**7 * Analysis: The decomposition of n factorization, should first find a minimum prime number k8 9 * Minimum prime number: "2". 2 is the smallest prime number, which is an even number and a prime number, and is then completed as follows:Ten One * (1) If the prime number is exactly equal to N, then the process of decomposing the factorization is finished and printed out. A - * (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. - the * (3) If n cannot be divisible by K, the first step is repeated with k+1 as the value of K. - * - * @paramthink about - */ + Public Static voidMain (String []args) { -Scanner s=NewScanner (system.in); +System.out.println ("Type a positive integer:"); A intn=s.nextint (); at intk=2;//define a minimum quality factor -System.out.print (n+ "="); - while(k<=n) {//to make a circular judgment - if(k==N) { - System.out.print (n); - Break; in}Else if(n%k==0){ -System.out.print (k + "*"); ton=n/K; +}Elsek++; - } the } *}
Java decomposition factorization