Computer Science, asked by nibeditap98, 11 months ago

Write a program in Java to check whether a number is a Armstrong number or not
Using scanner class & loop statement !!!

Answers

Answered by sakhareaakanksha
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^{3} + 3^{3}+5^{3}

=1+27+125

=153

Similar questions