由键盘输入一个数将它因式分解
1 import java.util.*; 2 public class Yinshifenjie{ 3 public static void main(String[] args){ 4 System.out.println("输入一个想要因式分解的数:"); 5 Scanner in=new Scanner(System.in); 6 int num=in.nextInt(); 7 if(num==1||num==2){ 8 System.out.println("因式分解的结果为:"+num); 9 } 10 System.out.println("因式分解为:"); 11 for(int x=2;x<=num;x++){ 12 boolean bool=true; 13 while(bool){ 14 if(num%x==0&&num!=x){ 15 int k=num/x; 16 num=k; 17 System.out.print(x+"*"); 18 }else if(num==x){ 19 System.out.print(x); 20 break; 21 }else{ 22 bool=false; 23 } 24 } 25 26 } 27 } 28 }