public static void main(String[] args) { Scanner scanner =new Scanner(System.in); while(scanner.hasNextLine()){ System.out.println("********开始计算*********"); int xx =Integer.parseInt(scanner.nextLine()); List list1=doaction(xx); if(test(list1,xx)){ System.out.println("*****计算结果为:*******"); String str = ""; for (int i = 0 ; i<list1.size();i++){ if (i== 0){ str=list1.get(0)+""; }else{ str = list1.get(i).toString() +"*"+str; } } System.out.println(str); }else { System.out.println("失败了"); } } } private static List doaction(int input){ int parameter =1 ; List list =new ArrayList(); for (int i = 1 ; input/(parameter)>1;i++ ){ for (int j =2;j<=(input/parameter);j++){ if ((input/parameter)%j==0){ parameter = j*parameter; list.add(j); break; } } } return list; } private static boolean test(List list,int testInt){ int testtest=1; for (int i = 0 ; i<list.size();i++){ testtest = testtest*Integer.parseInt(list.get(i).toString()); } if (testInt==testtest){ return true; }else{ return false; } } 结果: 22222 ********开始计算********* *****计算结果为:******* 271*41*2
java Math公约数
最新推荐文章于 2022-12-18 11:52:53 发布