-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathArmstrong.java
More file actions
29 lines (23 loc) · 750 Bytes
/
Copy pathArmstrong.java
File metadata and controls
29 lines (23 loc) · 750 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//Program to check whether a number is an armstrong number or not.
//A positive integer is called an Armstrong number of order n if the sum of cubes of each digits is equal to the number itself.
import java.util.Scanner;
public class Armstrong {
public static void main(String[] args)
{
System.out.println("Enter any number: ");
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m, rem, res = 0;
m = n;
while(m!= 0)
{
rem = m % 10;
res+= Math.pow(rem, 3);
m /= 10;
}
if(res == n)
System.out.println(n + " is an Armstrong number.");
else
System.out.println(n + " is not an Armstrong number.");
}
}