1 ImportJava.util.*;2 Public classlianxi04{3 Public Static voidMain (String []a) {4Scanner s =NewScanner (system.in);5System.out.print ("Please type a positive integer:"); 6 intn=s.nextint ();7 intk=2; 8System.out.print (n + "=" );9 while(k <=N) {Ten if(k = = N) {System.out.println (n); Break;} One Else if(n% k = = 0) {System.out.print (k + "*")); An = n/K; - } - Elsek++; the } - - } - +}
Program Analysis: ForNto decompose factorization, you should first find a minimum prime numberk, and then complete the following steps:
(1)If this prime number equalsN, the process of decomposing the factorization is finished and printed out.
(2)ifN <> k, butNcan bekdivisible, you should print outkvalue and use theNdivided bykthe Business,as the new positive integer youN,repeat the first step.
(3)ifNcannot bekdivisible, then usek+1as akthe value,repeat the first step.
Title: Decompose a positive integer into factorization. For example: Enter 90 and print out 90=2*3*3*5.