Program that reads two integer numbers and find all Armstrong number between them.

import java.io.*;
class number
{ int a,y,sum;

void armstrong(int x, int y)
{
for(int i=x;i<=y;i++)
{  int n=i;
sum=0;
boolean flag=true;
while(flag)
{    a=n%10;
n=n/10;
sum+=(a*a*a);
if(n==0)
flag=false;
}

if(sum==i)
{
System.out.println("Amstrong Number=  "+i+".");
flag=true;
}
}
}
}
class test
{ public static void main(String[] asd)throws IOException
{
BufferedReader obj= new BufferedReader(new InputStreamReader(System.in));

String num;
number a=new number();
System.out.println("Enter range of number::");
num=obj.readLine();
int n=Integer.parseInt(num);
num=obj.readLine();
int m=Integer.parseInt(num);
a.armstrong(n,m);

}
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s