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

Armstrong Number in Java: Class Public Static Void Int Int While

This document discusses how to check if a number is an Armstrong number in Java. It defines a class with a main method that takes a number as input, breaks it into digits, cubes each digit and sums them, and compares the result to the original number to determine if it is an Armstrong number, printing the appropriate message. The code sample shows how to check if 153 is an Armstrong number by performing these steps.

Uploaded by

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

Armstrong Number in Java: Class Public Static Void Int Int While

This document discusses how to check if a number is an Armstrong number in Java. It defines a class with a main method that takes a number as input, breaks it into digits, cubes each digit and sums them, and compares the result to the original number to determine if it is an Armstrong number, printing the appropriate message. The code sample shows how to check if 153 is an Armstrong number by performing these steps.

Uploaded by

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

Armstrong Number in Java

1. class ArmstrongExample{
2. public static void main(String[] args) {
3. int c=0,a,temp;
4. int n=153;//It is the number to check armstrong
5. temp=n;
6. while(n>0)
7. {
8. a=n%10;
9. n=n/10;
10. c=c+(a*a*a);
11. }
12. if(temp==c)
13. System.out.println("armstrong number");
14. else
15. System.out.println("Not armstrong number");
16. }
17. }

You might also like