-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisariumNumber.java
More file actions
49 lines (42 loc) · 797 Bytes
/
DisariumNumber.java
File metadata and controls
49 lines (42 loc) · 797 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.util.Scanner;
public class DisariumNumber {
static Scanner sc=new Scanner(System.in);
public static void main(String[] args) {
System.out.println("Enter a Number");
int no=sc.nextInt();
if(isDisariumNo(no)) {
System.out.println(no+" is a Disarium Number");
}
else {
System.out.println(no+" is Not a Disarium Number");
}
}
public static boolean isDisariumNo(int no) {
int sum=0;
int n=no;
int ct=countOfDigit(no);
while(n>0&&ct>0){
int last=n%10;
sum+=Power(last,ct);
n/=10;
ct--;
}
return sum==no;
}
public static int countOfDigit(int no){
int ct=0;
while(no>0){
ct++;
no/=10;
}
return ct;
}
public static int Power(int no,int pow){
int power=1;
while(pow>0){
power*=no;
pow--;
}
return power;
}
}