-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrintArmstrongNumbers.java
More file actions
34 lines (31 loc) · 916 Bytes
/
Copy pathPrintArmstrongNumbers.java
File metadata and controls
34 lines (31 loc) · 916 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
30
31
32
33
34
import java.util.Scanner;
import java.lang.Math;
public class PrintArmstrongNumbers {
//METHOD TO PRINT ARMSTRONG NUMBERS OF AN ARRAY
static void armstrong(int a[]){
for(int i=0; i<a.length; i++){
int sum=0, rem=0;
int a1=a[i];
while(a[i]>0){
rem= a[i]%10;
sum= sum+ rem*rem*rem;
a[i]= a[i]/10;
}
if(sum==a1){
System.out.println(sum);
}
}
}
public static void main(String args[]){
Scanner sc= new Scanner(System.in);
//ARRAY SIZE AND ELEMENTS INPUT
System.out.print("Enter size of array: ");
int size= sc.nextInt();
int arr[]= new int[size];
System.out.print("Enter array elements: ");
for(int i=0; i<size; i++){
arr[i]= sc.nextInt();
}
armstrong(arr);
}
}