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");}}}
No comments:
Post a Comment
if you have any doubts, Please let me know.
Your Truly
Shashank Porwal