标签:
//将一个正整数分解质因数,例如:输入90,打印出90=2*3*3*5
public class FenDou05 {
public static void zhiShu(int n){
for(int i=2;i<=n/2;i++){
if(n%i==0){
System.out.print(i+"*");
zhiShu(n/i);
}
}
System.out.print(n);
System.exit(0);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scanner=new Scanner(System.in);
System.out.println("请输入一个正整数:");
int n=0;
if(scanner.hasNextInt()){
n=scanner.nextInt();
if(n<=0){
System.out.println("您输入的不是正整数!");
return;
}else{
System.out.print(n+"=");
zhiShu(n);
}
}
}
}
标签:
原文地址:http://www.cnblogs.com/changyinlu/p/4693724.html