public class Demo { public static void main(String[] args) { int num = 153, num1, sum = 0; num1 = num; while (num != 0) { int digit = num % 10; sum = sum + (digit * digit * digit); num = num/10; } if (sum == num1) System.out.println(num1 + " is an Armstrong number"); else System.out.println(num1 + " is not an Armstrong number"); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter