A dazzling Armstrong Number Program
Armstrong Number Program: solved Java program for ICSE Class 9 Computer Applications with complete BlueJ code, explanation and sample output.
It is a number that is equal to the sum of cubes of its digits. For example 153
1^3+5^3+3^3=1+125+27=153.
For some basic concepts of java visit the link.
Conditional Constructs in JAVA
Write a program to accept a number and check whether it is an Armstrong number or not.
import java.io.*;
public class ArmstrongNumber //number = the sum of the cubes of the digits e.g., 153
{
public static void main() throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a number");
int num=Integer.parseInt(br.readLine());
int n=num;
int sum=0;
while(num!=0)
{
int rem=num%10;
rem=(int)Math.pow(rem,3);
sum+=rem;
num=num/10;
}
if(sum==n)
{
System.out.println("Armstrong number");
}
else
{
System.out.println("Not an Armstrong number");
}
}
}Output:
Enter a number
153
Armstrong number
Learn the basic concept of java https://youtu.be/TRm9r4gFTho
Related Posts
Continue learning with these related articles
Sum of First n Natural Numbers in Java (Loop and Formula)
Find the sum of the first n natural numbers in Java with a for loop, a while loop and the formula n(n + 1)/2, with a dry run and the sums of even numbers, odd numbers, squares and cubes.
Prime Number Program in Java: Check a Number and Print Primes in a Range
Check whether a number is prime in Java by counting its factors, a faster square-root method with isPrime(), and a program that prints all prime numbers in a range.

Encapsulation, Access Specifiers and Scope of Variables in Java for ICSE Class 10
ICSE Class 10 Computer Applications notes on encapsulation: private, default, protected and public access, data hiding with getter and setter methods, instance vs static (class) variables, local variables and scope, with a solved BankAccount program.