Showing posts with label disarium-number. Show all posts
Showing posts with label disarium-number. Show all posts

Wednesday, August 5, 2020

Write a program to input a number and check whether it is Disarium Number or not? (135=1^1+3^2+5^3=1+9+125=135)

78)  Write a program to input a number and check whether it is Disarium Number or not?  (135=11+32+53=1+9+125=135)


import java.util.*;
public class Disarium_num
{
    public static void main(String args[ ])
   {
           Scanner sc = new Scanner (System.in);
           System.out.println("Enter a number");
           int a = sc.nextInt();
           int k = a;
           int c = 0;
           while(k>0)
           {
               k=k/10;
               c++;
           }
           int r = 0;
           k=a;
           for(int i = c;i>=1;i--)
           {
               int d = k%10; 
               int x = (int)Math.pow(d,i);
               r=r+x;
               k=k/10;
           }
           if(r==a)
           {
               System.out.println("Entered number is a DISARIUM Number");
           }
           else
           {
               System.out.println("Entered number is not a DISARIUM Number");
           }
   }
}

Output : 


 



 jhvghvgk ;nkjn ,nkjhj