* WAP to Check whether a number is Armstrong or not
Answers
Answer:
Check Armstrong Number of n digits Enter an integer: 1634 1634 is an Armstrong number. In this program, the number of digits of an integer is calculated first and stored in n . And, the pow() function is used to compute the power of individual digits in each iteration of the second for loop.
People also ask
An Armstrong number is a number whose sum of cubes of digits is equal to the number itself.
For example:
153 = 1³+5³+3³
1+125+27
=153
Program:
import java. util.*;
class Armstrong
{
public static void main (string args [])
{
Scanner sc = new Scanner
int n, r, p, s=0, m;
System.out.println ("Enter a number");
n=sc.nextInt();
while
{
r=n%10
p=r*r*r;
s=s+p;
n=n/10;
}
if (m==s)
System.out.println (m+"is Armstrong");
else
System.out.println (m+"is not Armstrong");
}
}