- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java program to check whether the given number is an Armstrong number
An Armstrong number is a number which equals to the sum of the cubes of its individual digits. For example, 153 is an Armstrong number as −
153 = (1)3 + (5)3 + (3)3 153 1 + 125 + 27 154 153
Algorithm
1. Take integer variable Arms 2. Assign value to the variable 3. Split all digits of Arms 4. Find cube-value of each digits 5. Add all cube-values together 6. Save the output to Sum variable 7. If Sum equals to Arms print Armstrong Number 8. If Sum not equals to Arms print Not Armstrong Number
Example
import java.util.Scanner; public class ArmstrongNumber { public static void main(String args[]) { int number = 153; int check, rem, sum = 0; System.out.println("Enter the number to be verified:"); Scanner sc = new Scanner(System.in); number = sc.nextInt(); check = number; while(check != 0) { rem = check % 10; sum = sum + (rem * rem * rem); check = check / 10; } if(sum == number) System.out.println("Given number is an armstrong number."); else System.out.println("Given number is not an armstrong number."); } }
Output
Enter the number to be verified: 153 Given number is an armstrong number.
- Related Articles
- C# Program to Check Whether the Entered Number is an Armstrong Number or Not
- Java Program to Check Armstrong Number
- Java Program to Check Armstrong Number between Two Integers
- C++ Program to Check Armstrong Number
- Python Program to Check Armstrong Number
- C Program to Check Armstrong Number?
- Swift Program to Check Armstrong Number
- Haskell Program to Check Armstrong Number
- Java Program to Check whether the input number is a Neon Number
- Golang Program to Check For Armstrong Number
- Write a C# program to check if the entered number is Armstrong number?
- Program to check whether the given number is Buzz Number or not in C++
- Program to check whether given number is Narcissistic number or not in Python
- Java Program to Check if a given Number is Perfect Number
- Java program to check whether the number is divisible by 5

Advertisements