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

© 我有上将潘凤 中级黑马   /  2016-5-13 23:35  /  314 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

import java.util.Scanner;
class Disassemble {
        public static void main(String[] args) {
                Scanner hyh = new Scanner(System.in);
                System.out.println("请输入您要分解的数据.");
                int n = hyh.nextInt();
                String m = "";
                for (int x = n,i = 2,j = 0;i <=x;i++) {
                        if (x%i == 0 || i == x) {
                                j++;
                                if ((j == 1)) {
                                        x = x / i;
                                        m = ""+i;
                                        i =1;
                                }else {
                                        x = x / i;
                                        m = m+"×"+i;
                                        i = 1;
                                }
                        }
                }
                System.out.println(n+"="+m);
        }
}

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马