Java中简单算法之自幂数

img

img


求解!

public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int x=sc.nextInt(),cnt,s,t,t2;
        for(int i=1;i<=x;i++) {
            t = i;
            t2 = i;
            cnt = 0;
            while (t != 0) {
                t /= 10;
                cnt++;
            }
            s = 0;
            while (t2 != 0) {
                s += (t2 % 10) * 10 + cnt;
                t2 /= 10;
            }
            if (s == i) {
                System.out.println(i + "是自幂数");
                System.out.println("和是" + s);
            }
        }
    }