0

ARMSTRONG NUMBER

can someone pliz explain to me how this armstrong number function in java works.its the latest code on my profile

18th Oct 2017, 8:36 AM
Ricardo Chitagu
Ricardo Chitagu - avatar
2 Answers
+ 3
hi from right to left of a number extract digits n%10 rest is n//10 for every digit n: n*n*n add to sum if(3*3*3 +5*5*5+1*1*1) ==153, 153 is an armstrong number
18th Oct 2017, 9:20 AM
Oma Falk
Oma Falk - avatar
0
class ArmstrongExample{ public static void main(String[] args) { int c=0,a,temp; int n=153;//It is the number to check armstrong temp=n; while(n>0) { a=n%10; n=n/10; c=c+(a*a*a); } if(temp==c) System.out.println("armstrong number"); else System.out.println("Not armstrong number"); } } Im trying to understand how it works
18th Oct 2017, 8:37 AM
Ricardo Chitagu
Ricardo Chitagu - avatar