confused with int Assignments in Java -
i trying work on armstrong number, here code
public class newarmstrongnumber { public static void main(string[] args) { int num = 153,armnum=0; while(num>0){ int temp = num%10; armnum = armnum+(temp*temp*temp); num = num/10; } system.out.println(num==armnum); } }
the result getting false,may know why?
num decreasing /10 each time, , loop exits when num 0.
armnum potentially increasing each time goes through loop.
so unless armnum 0, false.
Comments
Post a Comment