Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis0
ARMSTRONG NUMBER
can someone pliz explain to me how this armstrong number function in java works.its the latest code on my profile
2 Respostas
+ 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
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