[java]代码库
import java.util.Scanner;
public class 分解质因数 {
public static int check(int i){
int temp,j,re=3;
if(i==2)
re=1;
else {
for (j = 2; j < i; j++) {
temp = i % j;
if (temp != 0)
re = 1;
else {
re = 0;
break;
}
}
}
return re;
}
public static void main(String[] args) {
int []value=new int[20];
int i,num,temp,j=0;
Scanner reader=new Scanner(System.in);
num=reader.nextInt();
for(i=2;i<num;){
if(check(i)!=1) {
i++;
continue;
}
if(num%i==0)
num=num/i;
else{
i++;
continue;
}
value[j]=i;
j++;
if (check(num)==1) {
value[j]=num;
break;
}
}
for(i=0;i<20;i++) {
System.out.print(value[i]);
if(value[i+1]==0)
break;
System.out.print("*");
}
}
}
[代码运行效果截图]