Array-promo

Question

Check whether the given number is armstrong number or not in a given range.

A positive number is called armstrong number if  sum of its own digits each raised to the power of the number of digits is equal to number

Enter the lower range
1
Enter the Upper range
500
Amstrong Numbers:
1
2
3
4
5
6
7
8
9
153
370
371
407

Share code with your friends

Share on whatsapp
Share on facebook
Share on twitter
Share on telegram

Code

import java.util.Scanner;
public class ArmstrongInRange
{
    public static void main(String[] args)
    {
        int c=0,r,temp=0,noOfDigits=0,lowerRange=0,upperRange=0,i=0;
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the lower range");
        lowerRange=sc.nextInt();
        System.out.println("Enter the Upper range");
        upperRange=sc.nextInt();
        System.out.println("Amstrong Numbers:");

        for(i=lowerRange;i<=upperRange;i++)
        {
            c=0;
            temp=i;
            noOfDigits=Integer.toString(i).length();
            while(temp>0)
            {
                r=temp%10;
                temp=temp/10;
                c=c+(int)(Math.pow(r,noOfDigits));
            }
            if(i==c)
            {
                System.out.println(i+" ");
            }

        }
    }
}

Coding Store

Sale

Original price was: ₹80.Current price is: ₹50.
Sale

Original price was: ₹250.Current price is: ₹150.
Sale

Original price was: ₹350.Current price is: ₹200.
Sale

Original price was: ₹80.Current price is: ₹50.
Sale

Original price was: ₹80.Current price is: ₹50.
Sale

Original price was: ₹80.Current price is: ₹50.
Sale
Mastering Array

Original price was: ₹80.Current price is: ₹50.
Sale

Original price was: ₹80.Current price is: ₹50.
Sale

Original price was: ₹80.Current price is: ₹50.
Sale

Original price was: ₹80.Current price is: ₹50.
Sale

Original price was: ₹250.Current price is: ₹150.
Sale

Original price was: ₹350.Current price is: ₹200.
Sale

Original price was: ₹80.Current price is: ₹50.
Sale

Original price was: ₹80.Current price is: ₹50.
Sale

Original price was: ₹80.Current price is: ₹50.
Sale
Mastering Array

Original price was: ₹80.Current price is: ₹50.
Sale

Original price was: ₹80.Current price is: ₹50.
Sale

Original price was: ₹80.Current price is: ₹50.
Sale

Original price was: ₹80.Current price is: ₹50.
Sale

Original price was: ₹250.Current price is: ₹150.
Sale

Original price was: ₹350.Current price is: ₹200.
Sale

Original price was: ₹80.Current price is: ₹50.
Sale

Original price was: ₹80.Current price is: ₹50.
Sale

Original price was: ₹80.Current price is: ₹50.
Sale
Mastering Array

Original price was: ₹80.Current price is: ₹50.
Sale

Original price was: ₹80.Current price is: ₹50.
Sale

Original price was: ₹80.Current price is: ₹50.

Leave a Reply

Your email address will not be published. Required fields are marked *