Computer Applications
Write a program to input a number and find whether the number is a Disarium number or not. A number is said to be Disarium if sum of its digits powered with their respective positions is equal to the number itself.
Sample Input: 135
Sample Output: 135 ⇒ 11 + 32 + 53 = 135
So, 135 is a Disarium number.
Java
Java Iterative Stmts
124 Likes
Answer
import java.util.Scanner;
public class KboatDisariumNumber
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter the number: ");
int num = in.nextInt();
int orgNum = num;
int digitCount = 0;
while (num != 0) {
num /= 10;
digitCount++;
}
num = orgNum;
int sum = 0;
while (num != 0) {
int d = num % 10;
sum += Math.pow(d, digitCount);
digitCount--;
num /= 10;
}
if (sum == orgNum)
System.out.println("Disarium Number");
else
System.out.println("Not a Disarium Number");
}
}Output

Answered By
40 Likes
Related Questions
Define a class to accept a number from user and check if it is an EvenPal number or not.
(The number is said to be EvenPal number when number is palindrome number (a number is palindrome if it is equal to its reverse) and sum of its digits is an even number.)
Example: 121 – is a palindrome number
Sum of the digits – 1+2+1 = 4 which is an even numberWhich of the following are entry controlled loops?
(a) for
(b) while
(c) do..while
(d) switch
- only a
- a and b
- a and c
- c and d