happy number by megamoff

class h{public static void main(String a[]){for(int i=1;i<2000;i++)if(y(i))System.out.println(i);}

\x09static boolean y(int n){if(n==1)return true;else if(n==4)return false;return y(step(n));}

\x09static int step(int n)
\x09{
\x09\x09int[]x=new int[(""+n).length()];
\x09\x09for(int i=0;i<(""+n).length();i++)
\x09\x09\x09x[i]=Integer.parseInt(new String(new byte[]{(""+n).getBytes()[i]}));
\x09\x09int a = 0;
\x09\x09for(int i=0;i<(""+n).length();i++)
\x09\x09\x09a+=x[i]*x[i];
\x09\x09return a;
}}

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page