Created
January 15, 2026 12:02
-
-
Save lakshyaraj2006/1321357d1d999d0ee9f7b5ac911c0161 to your computer and use it in GitHub Desktop.
Java Program to Check Armstrong number.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Scanner; | |
| import java.lang.Math; | |
| class Main { | |
| public static void main(String[] args) { | |
| Scanner sc = new Scanner(System.in); | |
| System.out.print("Enter a number: "); | |
| int num = sc.nextInt(); | |
| int temp = num; | |
| int digitsCnt = 0; | |
| while (temp != 0) { | |
| digitsCnt++; | |
| temp /= 10; | |
| } | |
| temp = num; | |
| int sum = 0; | |
| while (temp != 0) { | |
| int rem = temp % 10; | |
| sum = sum + (int) Math.pow(rem, digitsCnt); | |
| temp /= 10; | |
| } | |
| System.out.println(sum == num ? "Yes" : "No"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment