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
How many times will the following loop execute? Write the output of the code:
int x=10; while (true){ System.out.println(x++ * 2); if(x%3==0) break; }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 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++)