Wednesday, 29 May 2013

Nested Armstrong

import java.io.*;
class NestedArmstrong
{
    public static void main(String args[])throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int i,m,n,d,s;
        System.out.println("Enter the number to check the armstrong numbers upto the range u wish");
        n=Integer.parseInt(br.readLine());
        for(i=1;i<=n;i++)
        {
            m=i;
            s=0;
            while(m>0)
            {
                d=m%10;
                s=s+d*d*d;
                m=m/10;
            }
          if(s==i)
        {
            System.out.println(i);
        }
    }
    }
}
           
        

No comments:

Post a Comment