0% found this document useful (0 votes)
4 views1 page

Armstrong Program

The document contains a Java program that checks if a number is an Armstrong number. It reads an integer input, calculates the number of digits, and sums the cubes of its digits. Finally, it compares the sum to the original number and prints whether it is an Armstrong number or not.

Uploaded by

rishabkandoi305
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Armstrong Program

The document contains a Java program that checks if a number is an Armstrong number. It reads an integer input, calculates the number of digits, and sums the cubes of its digits. Finally, it compares the sum to the original number and prints whether it is an Armstrong number or not.

Uploaded by

rishabkandoi305
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Armstrong.

java
import java.util.Scanner;

class Armstrong
{
void main()
{
Scanner sc = new Scanner(System.in);

int n, i, j, d, s1, k, p, m;
n = sc.nextInt();

p = 0;
i = n;
while (i > 0) {
i /= 10;
p++;
}

s1 = 0;
i = n;
while (i > 0) {
d = i % 10;

k = 1;
m = 1;
while (k <= p) {
m =m*d;
k++;
}

s1 =s1+ m;
i =i/ 10;
}

if (s1 == n)
System.out.println(n + " is an Armstrong Number.");
else
System.out.println(n + " is NOT an Armstrong Number.");
}
}

You might also like