Q- Write a program to check whether a number is Armstrong or not?


import java.io.*;
public class arm
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n=0;
System.out.println("ENTER ANY NUMBER");
n=Integer.parseInt(br.readLine());
boolean f=arm.armstrong(n);
if(f==true)
System.out.println("the no. is armstrong");
else
System.out.println("not armstrong");
}
static boolean armstrong(int n)
{
int a=0,s=0,num=n;
while(n>0)
{
a=n%10;
s=s+a*a*a;
n=n/10;
}
if(num==s)
{
return true;
}
else
{
return false;
}
}
}
Advertisements

One thought on “Q- Write a program to check whether a number is Armstrong or not?

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s