17-08-07 求质数因子

时间:2021-08-23 14:43:42

输入一个正整数,按照从小到大的顺序输出它的所有质数的因子

public static void num() {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
System.out.print(n + "=");
for (int i = 2; i < n + 1; i++) {
while (n % i == 0 && n != i) {
n /= i;
System.out.print(i + "*");
}
if (n == i) {
System.out.println(i);
break;
}
}
}