Array-promo

Question

Program to determine whether a given number is a Disarium number in a given range.

(A number is said to be the Disarium number when the sum of its digit raised to the power of their respective positions is equal to the number itself.)

Enter the lower range
1
Enter the Upper range
500
Disarium  Numbers:1    2    3    4    5    6    7    8    9    89    135    175

Share code with your friends

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

Code

import java.util.Scanner;
public class disariumNumberInRange
{
    public static void main(String[] args)
    {
        int  sum = 0, rem = 0, temp=0,i=0,upperRange=0,lowerRange=0,len=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.print("Disarium  Numbers:");
        for(i=lowerRange;i<=upperRange;i++)
        {
            temp=i;
            while(temp>0)
            {
                len=len+1;
                temp=temp/10;
            }
            sum=0;
            /*Makes a copy of the original number num*/
            temp = i;

            /*Calculates the sum of digits powered with their respective position */
            while(temp > 0)
            {
                rem = temp%10;
                sum = sum + (int)Math.pow(rem,len);
                temp = temp/10;
                len--;
            }

        /*Checks whether the sum is equal to the number itself  */
            if(sum == i)
            {
                System.out.print(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 *