Factor decomposition
/* Factor decomposition is a very basic mathematical operation and is widely used. The following program performs factorization of integer n(n>1). For example, if n=60, then the output is: 2 2 3 5. Please add the missing parts. */ public class factorization { public static void f(int n) { for (int i = 2; i < n / 2; i++) { while(n%i==0){ // Fill in the blanks System.out.printf ("%d ", i); n = n / i; } } if (n > 1) System.out.printf("%d/n", n); } public static void main(String[] args) { f(60); } } Running results:
2 2 3 5
Minimum common multiple
/* It is a very common operation to find the minimum common multiple of two numbers. For example, the minimum common multiple of 3 and 5 is 15. The minimum common multiple of 6 and 8 is 24. The following code finds its minimum common multiple for the given two positive integers. Please fill in the missing code to make the program run as efficiently as possible. Save the answers to fill in the blanks (only the answers in the blanks, not including the question page) into the corresponding question number in the candidate folder "Answer.txt". */ public class Minimum common multiple { public static int f(int a, int b) { int i; for(i=a;;i+=a){ // Fill in the blanks if(i%b==0) return i; } } public static void main(String[] args){ System.out.println(f(6,8)); } } Running results:
Copy the code as follows: 24