Computer Science, asked by xXitzSweetMelodyXx, 4 months ago

write a program to accept any number and check whether it is a disarium number or not

pls answer​

Answers

Answered by Anonymous
8

public class DisariumNumber

{

//calculateLength() will count the digits present in a number

public static int calculateLength(int n){

int length = 0;

while(n != 0){

length = length + 1;

n = n/10;

}

return length;

}

public static void main(String[] args) {

int num = 175, sum = 0, rem = 0, n;

int len = calculateLength(num);

//Makes a copy of the original number num

n = num;

//Calculates the sum of digits powered with their respective position

while(num > 0){

rem = num%10;

sum = sum + (int)Math.pow(rem,len);

num = num/10;

len--;

}

//Checks whether the sum is equal to the number itself

if(sum == n)

System.out.println(n + " is a disarium number");

else

System.out.println(n + " is not a disarium number");

}

}

Answered by Anonymous
10

\huge\mathtt \red{A} \blue{n} \pink{s} \purple{w} \blue{e} \orange{r}

How To Check Whether Given Number Is Disarium Or Not In Java?

int noOfDigits = Integer. toString(inputNumber). ...

int copyOfInputNumber = inputNumber; Step 4 : Extract lastDigit from inputNumber .

int lastDigit = inputNumber % 10; ...

sum = sum + (int) Math. ...

inputNumber = inputNumber / 10; ...

Output 1 : ...

Output 2 : ...

Output : .....

\red{\:i \: hope \: it \: is \: helpful \: for \: you}

Similar questions