Small exercise _ num1, exercise _ num1
Question: decompose a positive integer into a prime factor. For example, enter 90 and print the output 90 = 2*3*3*5.
1/* 2 decomposition prime factor 3 */4 import java. util. *; 5 class num1 6 {7 public static void main (String [] args) throws Exception 8 {9 boolean B = true; 10 while (B) 11 {12 try13 {14 then SC = new then (System. in); 15 System. out. println ("************************************* *******************"); 16 System. out. println ("START ___ enter a positive integer greater than one:"); 17 int n = SC. nextInt (); 18 int k = 2; 19 System. out. print (n + "="); 20 while (k <= N) 21 {22 if (k = n) // determines whether n is equal to k. if the equal value indicates that n is a prime number, the search is complete, break! 23 {24 System. out. println (n); break; 25} 26 else if (n % k = 0) // at this time, n is definitely not a prime number, and k is used for remainder. if it can be divisible, this k is a prime factor of 27 {28 System. out. print (k + "*"); n = n/k; 29} 30 else // at this time, n is not a prime number, and k is not a prime factor, from small to large, start searching for the next prime factor 31 k ++; 32} 33 while (k> n) 34 {35 System. out. println ("<ERROR-enter a positive integer greater than 1>"); break; 36} 37} 38 catch (Exception e) 39 {40 System. out. println ("<!! The value you entered is not a positive integer greater than 1 or exceeds the calculation range!> "); 41} 42 seconds scgoon = new second (System. in); 43 System. out. println ("___________________________________________________"); 44 System. out. println ("press enter to continue, enter exit to exit"); 45 String sg = scgoon. nextLine (); 46 if (sg. equals ("exit") 47 {B = false;} 48} 49} 50}