题目:
将一个正整数进行分解质因数操作
例如: 输入90
结果为2 * 3 * 3 * 5
import java.util.Scanner;
class Practice7 {
public static void main (String[] args){
int num = 0;
int i = 2;
boolean flag = true;
Scanner sc = new Scanner(System.in);
while(num < 2){
System.out.print("请输入一个正整数:");
num = sc.nextInt();
}
while(i <= num){
while(num % i == 0){
if(flag == true){
System.out.print(i);
num /= i;
flag = false;
continue;
}
System.out.print(" * "+i);
num /= i;
}
i += 1;
}
}
}
演示结果: