Tuesday, 5 February 2019

5.How to find armstrong number in java.


Description:
Write a sample code  to find Armstrong number in java

Code:
?
1
2
3
4
5
6
7
8
9
10

public class Armstrong_NO {
public static void main(String[] args) { int n=159; int temp=n; int r,sum=0; while(n>0) { r=n%10; n=n/10; sum =sum+ r* r*r; } if(temp==sum) System.out.println(" Armstrong : "); else System.out.println("This is not Armstrong"); } }


Output:
This  is not  Armstrong

No comments:

Post a Comment