//题目:将一个正整数分解质因数。例如:输入90,打印出90=2*3*3*5。
-----------------------------------------------------------------------------------------
package shiti;
import java.util.Scanner;
public class Test03 {
public static void main(String[] args) {
System.out.println("请输入一个正整数:");
int num = new Scanner(System.in).nextInt();
int count = num;
StringBuffer sb = new StringBuffer();
for (int i = 2; i <= count; i++) {
if (count % i == 0) {
count /= i;
sb.append(i + "*");
i--;
}
}
System.out.println(num + "="
+ sb.substring(0, sb.length() - 1).toString());
}
}
|
|