Armstrong Number in java
The Charm of Armstrong Numbers: A Java Exploration
In the realm of mathematics and programming, Armstrong numbers, also known as narcissistic numbers, stand as intriguing numerical phenomena. These special numbers possess a unique quality that captures the imagination of mathematicians and programmers alike. Today, we embark on a journey to unravel the mysteries of Armstrong numbers using Java, a versatile programming language that empowers us to explore and identify these enigmatic digits.
## Defining Armstrong Numbers
An Armstrong number is a specific type of number that exhibits a remarkable property. It is an n-digit number for which the sum of its own digits, each raised to the power of n, is equal to the number itself. an n-digit number,
Source code of Program
//For example: 153
//= 1*1*1 + 5*5*5 + 3*3*3
// 153 is an Armstrong number.
import java.util.Scanner;
class armstrongnumber
{
public static void main(String ar[])
{
Scanner obj=new Scanner(System.in);
int cb,b,s;
System.out.println("Enter a number");
int num=obj.nextInt();
int num1=num;
s=0;
while(num!=0)
{
b=num%10;
cb=b*b*b;
s=s+cb;
num/=10;
}
if(s==num1)
{
System.out.println("Its an Amstrong number");
}
else
{
System.out.println("Its not an amstrong number");
}
}
}
## The Beauty of Numerical Symmetry
Armstrong numbers possess an inherent symmetry that is both elegant and intriguing. This symmetry arises from the fact that each digit is treated individually, and their powers are carefully summed to recreate the original number. When we find an Armstrong number, we witness the harmony between mathematics and logic.
Armstrong Number in java
## Java: The Toolkit for Exploration
Java, as a robust and versatile programming language, provides an ideal toolkit for exploring Armstrong numbers. With its mathematical capabilities and user-friendly structure, Java allows us to build a program that identifies these numbers with ease.
## The Java Code for Armstrong Numbers
Let's delve into a Java program that identifies Armstrong numbers. This code prompts the user to input a number and checks if it meets the Armstrong criteria. Here's the code
This Java program begins by prompting the user to enter a number. It then utilizes the `isArmstrong` method to check if the number is indeed an Armstrong number. The logic involves calculating the sum of the digits raised to the power of the number of digits and comparing it to the original number. The `count Digits` method counts the number of digits in the input number.
## Exploring Armstrong Numbers
With this Java program at our disposal, we have the means to explore and identify Armstrong numbers. Whether you're captivated by the mathematical beauty of these numbers or intrigued by the logic behind their identification, Java empowers us to embark on a numerical adventure.
So, dear reader, as you venture further into the world of mathematics and programming, remember that Armstrong numbers are not mere digits; they are the embodiment of numerical symmetry and mathematical intrigue. Embrace the code and logic that reveal their hidden properties, and let the journey into Armstrong numbers be a testament to the beauty of numbers in the world of Java programming.
![]() |
| Output Screen |

0 Comments