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
110 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
35 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 numberTo execute a loop 10 times, which of the following is correct?
- for (int i=11;i<=30;i+=2)
- for (int i=11;i<=30;i+=3)
- for (int i=11;i<20;i++)
- for (int i=11;i<=21;i++)
Rewrite the following do while program segment using for:
x = 10; y = 20; do { x++; y++; } while (x<=20); System.out.println(x * y );
To execute a loop 5 times, which of the following is correct?