A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© yu244934256 中级黑马   /  2016-9-23 00:05  /  1566 人查看  /  9 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

1.从2开始
2.能被最小公约数整除就一直除
3.当整除后的数等于本身就退出
  1.         public static void primeFactor(int a) {
  2.                 int z = 2;
  3.                 while (a >= z) {
  4.                         if (z == a) {
  5.                                 System.out.print(z);
  6.                                 break;
  7.                         } else if (a % z == 0) {
  8.                                 System.out.print(z + "*");
  9.                                 a = a / z;
  10.                         } else {
  11.                                 z++;
  12.                         }
  13.                 }
  14.                 System.out.println();
  15.         }
复制代码

9 个回复

正序浏览
不错不错
回复 使用道具 举报
可以,很强势,学习到了~
回复 使用道具 举报
没做会一道题就会有一点成就感
回复 使用道具 举报
public class Zhishu {
        public static void main(String[] args) {
                Scanner sc = new Scanner(System.in);
                System.out.println("shuru");
                int x = sc.nextInt();
                StringBuffer sb = new StringBuffer();
                sb.append(x).append("=");
                for (int i = 2; i <= x; i++) {
                        while (x % i == 0) {
                                if (x % i == 0) {
                                        x /= i;
                                        sb.append(i).append("*");
                                }
                        }
                }
                System.out.println(sb.substring(0, sb.length() - 1));
        }
}
回复 使用道具 举报
没上过数学的我连分解质因数都没听说过
回复 使用道具 举报
强!观摩
回复 使用道具 举报
星哥大周 来自手机 初级黑马 2016-9-23 01:11:45
板凳
原来如此
回复 使用道具 举报
不错,学习了
回复 使用道具 举报
逻辑很清晰
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马