Skip to content

Instantly share code, notes, and snippets.

@lakshyaraj2006
Created January 15, 2026 12:02
Show Gist options
  • Select an option

  • Save lakshyaraj2006/1321357d1d999d0ee9f7b5ac911c0161 to your computer and use it in GitHub Desktop.

Select an option

Save lakshyaraj2006/1321357d1d999d0ee9f7b5ac911c0161 to your computer and use it in GitHub Desktop.
Java Program to Check Armstrong number.
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