0
Help me with this thing.
Why does this if () condition is not working when we enter input as 371 ?? import java.util.Scanner; class armStrong{ public static void main(String []args){ Scanner sc=new Scanner(System.in); int num,arm=0,a; System.out.println("Enter the num which you want to check which is < 1000= "); num=sc.nextInt(); while(num!=0){ a=num%10; arm=arm+(a*a*a); num=num/10; } System.out.println(arm); if(arm==num){ System.out.println("The integer is an Armstrong number."); } else{ System.out.println("The integer is not an Armstrong number."); } } }
5 Answers
+ 2
Because the value of num is lost in the while loop. Store the value of the num in a variable before the loop and check arm with that variable
+ 1
Riya Patel just one question I want to ask you. Have you downvoted by answer?
+ 1
No problem
0
Thank you. It worked
0
By mistake it happened. Sorry



