Deserium Number | Java program to check whether a number is Deserium number or not ; Returns count of digits in n . ; Returns true if x is Diserium ; Compute powers of digits from right to left . ; If sum of powers is same as given number . ; Driver code
import java . util . Scanner ; class Deserium { static int countDigits ( int n ) { int c = 0 ; do { c ++ ; n = n / 10 ; } while ( n != 0 ) ; return c ; } static boolean isDeserium ( int x ) { int temp = x ; int p = countDigits ( x ) ; int sum = 0 ; while ( x != 0 ) { int digit = x % 10 ; sum += Math . pow ( digit , p ) ; p -- ; x = x / 10 ; } return ( sum == temp ) ; } public static void main ( String [ ] args ) { int x = 135 ; if ( isDeserium ( x ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }