Given a starting number and the ending number the task is to find the all the Armstrong Number present in that given range and also to display it’s frequency.
Armstrong Number is a number whose sum of the power of digits is equal to the original number where power is number of digits in the number.
Example 1: 153. 13+53+33 = 1+125+27 = 153.
Example 2: 1634. 14+64+34+44 = 1+1296+81+256 = 1634.
Java
import java.util.*;
public class ArmstrongNumberRange
{
public static void main(String args[])
{
int start=0,end=0,r=0,s=0,temp=0,count=0,frequency=0;
Scanner sc=new Scanner(System.in);
System.out.print("Enter a starting range: ");
start=sc.nextInt();
System.out.print("Enter a ending range: ");
end=sc.nextInt();
System.out.println("Armstrong Numbers in the given range are:-");
for(int i=start;i<=end;i++)
{
temp=i;
while(temp>0)
{
count++;
temp=temp/10;
}
temp=i;
while(temp>0)
{
r=temp%10;
s=s+(int)Math.pow(r,count);
temp=temp/10;
}
if(s==i)
{
System.out.println(i);
frequency++;
}
s=0;count=0;
}
System.out.println("Frequency: "+frequency);
}
}Java