Computer Science, asked by Rainbowgain, 3 months ago

write a program in java to print disarium number​

Answers

Answered by labdhee82
0
  1. public class DisariumNumber.
  2. {
  3. //calculateLength() will count the digits present in a number.
  4. public static int calculateLength(int n){
  5. int length = 0;
  6. while(n != 0){
  7. length = length + 1;
  8. n = n/10;
Answered by Anisha5119
5

import java.util.*;

class Disarium

{

public static void main()

{

Scanner sc= new Scanner (System.in);

{

System.out.println(" Enter a number");

int num= sc.nextInt();

int c=num,d=0,sum=0;

String s= Integer.toString(num);

int l= s.length();

while(c>0)

{

d=c%10;

sum=sum+(int)Math.pow(d,l);

l--;

c=c/10;

}

if(sum==num)

System.out.println("Disarium number");

else

System.out.println("Not a Disarium number");

}

}

Similar questions