- import java.util.Scanner;
- public class Test56 {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.println("输入数字:");
- int in = sc.nextInt();
- StringBuilder sb = new StringBuilder();
- int count = 0;
- String str = method(sb, in,count);
- System.out.println(in + "=" + str);
- }
- private static String method(StringBuilder sb, int in,int count) {
- for (int i = 2; i <= in; i++) {
- if (in % i == 0) {
- count++;
- if (i == in) {
- sb.append(i);
- break;
- } else {
- in = in / i;
- sb.append(i).append("*");
- return method(sb, in,count);
- }
- }
- }
- if (count == 1) {
- sb.append("*").append(1);
- }
- return sb.toString();
- }
- }
复制代码 |