
Write a program â??checkHighestArmstrongâ?? to find the highest Armstrong number in a given array of integers. If there is no Armstrong number in the input array, then return 0. Armstrong numbers are those numbers whose sum of their own digits to the power of the number of digits is equal to the digit itself. Example: 1634 = 1^4 + 6^4 + 3^4 + 4^4 (i.e. sum of 1 to the power of 4, 6 to the power of 4,3 to the power of 4 and 4 to the power of 4 is 1634) Hence 1634 is an Armstrong number. The input array should contain only 5 positive integers between 100 to 99999999 (both inclusive). Contract: checkHighestArmstrong (int[] inputArray) -> int Test case: int[] inputArray = {1631,1634,1599,1789,14784}; checkHighestArmstrong (inputArray) -> 1634 For any error in business validations (i.e., if the input array does not contain 5 elements or if any element of the array is not between 100 to 99999999), return message should be -1.

import java.lang.Math;
class arm{ public static void main(String atgs[]){ int array[]={1631,1634,1599,1789,14784}; int a[]=new int[5]; for(int i=0;i<5;i++){ int num=array[i]; int n=num; int no=num; int sum=0; int count=0;
while(num>=1){ num/=10; count++; } while(no>=1){ int rem=no%10; no/=10; sum+=Math.pow(rem,count); } if(n==sum){ System.out.println("yes"); a[i]=n; } else a[i]=0; } int max=a[0]; for(int i=1;i<5;i++){ if(a[i]>max) max=a[i];
}
System.out.println("max="+max); }
}

import java.lang.Math;
class arm{ public static void main(String atgs[]){ int array[]={1631,1634,1599,1789,14784}; int a[]=new int[5]; for(int i=0;i<5;i++){ int num=array[i]; int n=num; int no=num; int sum=0; int count=0;
while(num>=1){ num/=10; count++; } while(no>=1){ int rem=no%10; no/=10; sum+=Math.pow(rem,count); } if(n==sum){ System.out.println("yes"); a[i]=n; } else a[i]=0; } int max=a[0]; for(int i=1;i<5;i++){ if(a[i]>max) max=a[i];
}
System.out.println("max="+max); }
}

import java.lang.Math;
class arm{ public static void main(String atgs[]){ int array[]={1631,1634,1599,1789,14784}; int a[]=new int[5]; for(int i=0;i<5;i++){ int num=array[i]; int n=num; int no=num; int sum=0; int count=0;
while(num>=1){ num/=10; count++; } while(no>=1){ int rem=no%10; no/=10; sum+=Math.pow(rem,count); } if(n==sum){ System.out.println("yes"); a[i]=n; } else a[i]=0; } int max=a[0]; for(int i=1;i<5;i++){ if(a[i]>max) max=a[i];
}
System.out.println("max="+max); }
}

import java.lang.Math;
class arm{ public static void main(String atgs[]){ int array[]={1631,1634,1599,1789,14784}; int a[]=new int[5]; for(int i=0;i<5;i++){ int num=array[i]; int n=num; int no=num; int sum=0; int count=0;
while(num>=1){ num/=10; count++; } while(no>=1){ int rem=no%10; no/=10; sum+=Math.pow(rem,count); } if(n==sum){ System.out.println("yes"); a[i]=n; } else a[i]=0; } int max=a[0]; for(int i=1;i<5;i++){ if(a[i]>max) max=a[i];
}
System.out.println("max="+max); }
}

import java.lang.Math;
class arm{ public static void main(String atgs[]){ int array[]={1631,1634,1599,1789,14784}; int a[]=new int[5]; for(int i=0;i<5;i++){ int num=array[i]; int n=num; int no=num; int sum=0; int count=0;
while(num>=1){ num/=10; count++; } while(no>=1){ int rem=no%10; no/=10; sum+=Math.pow(rem,count); } if(n==sum){ System.out.println("yes"); a[i]=n; } else a[i]=0; } int max=a[0]; for(int i=1;i<5;i++){ if(a[i]>max) max=a[i];
}
System.out.println("max="+max); }
}

import java.lang.Math;
class arm{ public static void main(String atgs[]){ int array[]={1631,1634,1599,1789,14784}; int a[]=new int[5]; for(int i=0;i<5;i++){ int num=array[i]; int n=num; int no=num; int sum=0; int count=0;
while(num>=1){ num/=10; count++; } while(no>=1){ int rem=no%10; no/=10; sum+=Math.pow(rem,count); } if(n==sum){ System.out.println("yes"); a[i]=n; } else a[i]=0; } int max=a[0]; for(int i=1;i<5;i++){ if(a[i]>max) max=a[i];
}
System.out.println("max="+max); }
}

Java check highest Armstrong Number
import java.util.*;
class CheckHighestArmstrong
{
public static void main(String[] args)
{
int max = Integer.MIN_VALUE;
Scanner input=new Scanner(System.in);
System.out.println("Enter Array Elements between 100 and 99999999: ");
int arr[]=new int[5];
for(int i=0;i<arr.length;i++){
int num=input.nextInt();
if((num<100)||(num>99999999)){
System.out.print("Re-enter Numbers.It is out of range.");
num=input.nextInt();
arr[i]=num;
}
else{
arr[i]=num;
}
}
for(int i=0;i<arr.length;i++){
int k=arr[i];
int n=k;
int d=0,s=0;
while(n>0)
{
d=n%10;
s=s+(d*d*d);
n=n/10;
}
if(k==s){
if (k > max) {
max = k;
}
}
else{
}
}
System.out.println(max);
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.