Write a program in Java to check whether a number is a Armstrong number or not
Using scanner class & loop statement !!!
Answers
Answered by
2
import java.util.*;
public class armstrong
{
void main( )
{
Scanner in=new Scanner(system.in);
int n,r,t,s=0;
System.out.println("enter a number");
n=in.nextInt( );
t=n;
while(n>0)
{
r=n%10;
s=s+(int) (Math.pow(r,3));
n=n/10;
}
if(s==t)
sopln("armstrong no")
else
sopln("not a armstrong no")
}
}
Explanation:
Armstrong no is a number where the sum of cubes of each digit is equal to the number itself
example:
153
=
=1+27+125
=153
Similar questions
Geography,
5 months ago
Social Sciences,
5 months ago
Sociology,
5 months ago
Social Sciences,
11 months ago
Math,
11 months ago
Math,
1 year ago