VOOZH about

URL: https://www.simplilearn.com/tutorials/java-tutorial/armstrong-number-in-java

⇱ Armstrong Number in Java: Everything You Need to Know


HomeResourcesSoftware DevelopmentJava Tutorial for BeginnersArmstrong Number in Java: Everything You Need to Know
Tutorial Playlist
Java Tutorial for BeginnersOverview
10 Reasons That Explain Why You Need to Learn JavaLesson - 1What is Java: A Beginners Guide To JavaLesson - 2JDK in Java: Meaning, Components, and UsesLesson - 3One-Stop Solution for Java Installation in WindowsLesson - 4How to Get Started With Eclipse IDE?Lesson - 5What Are Java Strings And How to Implement Them?Lesson - 6Arrays In Java: Declare, Define, and Access ArrayLesson - 7Collections in Java: A Complete Beginner's GuideLesson - 8What Are Java Classes and Objects and How Do You Implement Them?Lesson - 9How to Implement the Revolutionary OOPs Concepts in JavaLesson - 10What is Encapsulation in Java and How to Implement It?Lesson - 11What is an Abstract Class in Java and How to Implement It?Lesson - 12What is Inheritance in Java and How to Implement ItLesson - 13What is Java Interface and Why it's Needed?Lesson - 14What is Polymorphism in Java and How to Implement It?Lesson - 15What is a Java Lambda Expression and How to Implement It?Lesson - 16Your One-Stop Solution for Multithreading in JavaLesson - 17Type Casting in Java: Everything You Need to KnowLesson - 18Scanner In Java: Everything You Need to KnowLesson - 19Access Modifiers in Java: Everything You Need to KnowLesson - 20Armstrong Number in Java: Everything You Need to KnowLesson - 21Singleton Class in Java: Everything You Need to KnowLesson - 22Final Keyword in Java: All You Need to KnowLesson - 23Wrapper Class in Java: A Complete GuideLesson - 24Fibonacci Series in Java: Explained with ExamplesLesson - 25Top 25 Pattern Programs in Java For Printing PatternsLesson - 26Top Brilliant Java Project Ideas For BeginnersLesson - 27Prime Number Program in JavaLesson - 28Java EE Tutorial: All You Need To Know About Java EELesson - 29What is Exception Handling in Java?Lesson - 30What Is Java JDBC? The Complete ReferenceLesson - 31What is Java API and The Need for Java APIs?Lesson - 32Introduction To Java Servlets and Its Life-CycleLesson - 3310 Best Java Frameworks You Should Know in 2026Lesson - 34All You Need to Know to Implement JUnit Testing in JavaLesson - 35What Is Junit? a Look Into the Best Java Testing FrameworkLesson - 36Java Programming: The Complete Reference You NeedLesson - 37The Differences Between C++ and Java That You Need To KnowLesson - 38Java vs. Python: Which is the Best Programming Language?Lesson - 39Java vs JavaScript: Know The 8 Major DifferencesLesson - 40Difference Between Encapsulation and Abstraction ExplainedLesson - 41Ruby on RailsLesson - 42The Best Guide to Know What Is Vue JSLesson - 43

Armstrong Number in Java: Everything You Need to Know

Lesson 21 of 43By Simplilearn

Last updated on Jul 31, 202510786

Table of Contents

View More

What is an Armstrong Number?

Mathematicians refer to a particular form of number as an Armstrong number, also known as a narcissistic number or a pluperfect digital invariant. A number that is the product of its own digits raised to the power of the number of digits is said to be a prime number. Because 1 + 5 + 3 equals 153, the number 153 is an armstrong number in Java. Armstrong numbers essentially show a peculiar self-referential feature.

How do Armstrong Numbers Work?

It's intriguing how the armstrong number program in java works. Consider dividing a number into its component digits, and then multiplying each digit by a predetermined power. Then you add these powerful digits together. You have an Armstrong number if the sum is the same as the initial number. These numbers are relatively uncommon but may be systematically detected, which results in an intriguing mathematical phenomenon.

What is the Armstrong Number Program in Java?

A great example of how mathematical ideas can be converted into code is the Armstrong number program in Java. For loops are used in this Java program to identify Armstrong numbers, which are numbers equal to the sum of their digits raised to the power of the number of digits. The program determines if a user-inputted number is an Armstrong number or not by doing computations using loops and arithmetic operations. By providing an interactive means to study and comprehend the distinctive aspects of these fascinating numerical events, it exemplifies the connection between mathematics and programming.

Armstrong Number Program in Java

import java.util.Scanner;

public class ArmstrongNumber {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter a number: ");

        int number = scanner.nextInt();

        scanner.close();

        if (isArmstrong(number)) {

            System.out.println(number + " is an Armstrong number.");

        } else {

            System.out.println(number + " is not an Armstrong number.");

        }

    }

    // Function to check if a number is an Armstrong number

    public static boolean isArmstrong(int num) {

        int originalNum = num;

        int result = 0;

        int n = String.valueOf(num).length();

        while (num != 0) {

            int digit = num % 10;

            result += Math.pow(digit, n);

            num /= 10;

        }        

        return result == originalNum;

    }

}

This program takes an integer input from the user and checks if it's an Armstrong number or not.

Here's How to Land a Top Software Developer JobAI-Powered Full Stack Developer ProgramExplore Program

Conclusion

The fascinating mathematical objects known as Armstrong numbers in Java exhibit a special self-referential characteristic. It requires dissecting numbers, increasing digits to powers, then adding them all together to locate them. You can experiment with and learn about Armstrong numbers on your own by developing a straightforward Java program.

If you are looking to enhance your software development skills, we would highly recommend you to check Simplilearn’s Professional Certificate Program in Full Stack Web Development - MERN. This program, in collaboration with IIT Madras, can help you hone the right skills and make you job-ready in no time.

If you have any questions or doubts, feel free to post them in the comments section below. Our team will get back to you at the earliest.

FAQs

1. What is the significance of Armstrong numbers?

Armstrong numbers hold mathematical intrigue due to their self-referential property where a number is equal to the sum of its digits raised to certain powers. They offer a unique way to connect mathematical concepts with programming, enhancing our understanding of number theory and coding practices.

2. Can Armstrong numbers be negative? 

No, Armstrong numbers are defined for positive integers only. They are not applicable to negative numbers or fractions, as the sum of powered digits doesn't hold the same property for these cases.

3. How many Armstrong numbers are there in Java?

There is a finite count of Armstrong numbers in Java, and they are relatively rare. The largest Armstrong number within Java's data types range is 9,926,315, the only 9-digit Armstrong number.

4. Is 1234 an Armstrong number?

No, 1234 is not an Armstrong number. It doesn't satisfy the condition where the sum of its digits raised to the power of the number of digits equals the original number.

5. Are there applications of Armstrong numbers in real?

While Armstrong numbers might not have direct practical applications, they serve as an excellent exercise in coding, promoting logical thinking and algorithm development. They also highlight the elegance of mathematical patterns in unexpected places.

About the Author

πŸ‘ Simplilearn
Simplilearn

Simplilearn is one of the world’s leading providers of online training for Digital Marketing, Cloud Computing, Project Management, Data Science, IT, Software Development, and many other emerging technologies.

View More

Recommended Programs

πŸ‘ Full Stack Java Developer Masters Program

Full Stack Java Developer Masters Program

1029 Learners
Lifetime Access*
πŸ‘ Full Stack Web Developer - MERN

Full Stack Web Developer - MERN

358 Learners
Lifetime Access*
πŸ‘ Java Certification Training

Java Certification Training

16365 Learners

*Lifetime access to high-quality, self-paced e-learning content.

Explore Category
  • Acknowledgement
  • PMP, PMI, PMBOK, CAPM, PgMP, PfMP, ACP, PBA, RMP, SP, OPM3 and the PMI ATP seal are the registered marks of the Project Management Institute, Inc.
  • *All trademarks are the property of their respective owners and their inclusion does not imply endorsement or affiliation.
  • Career Impact Results vary based on experience and numerous factors.