Saturday, 1 December 2012

ARMSTRONG NUMBER


import java.io.*;
class armstrong1
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n,m,c=0,i;
double s=0,d;
System.out.println("Enter the number to check wheather the number is armstrong or not  : -  ");
n=Integer.parseInt(br.readLine());
m=n;
while(m>0)
{
c++;
m=m/10;
    }
   
for(m=n;m>0;m=m/10)
{
d=m%10;
s=s+Math.pow(d,c);
    }
        if(n==(int)(s))
    {
System.out.println(n+" is an armstrong number ");
    }
    else
{
System.out.println(n+" is not an armstrong number ");
    }  
    }
}

No comments:

Post a Comment