-
-
Notifications
You must be signed in to change notification settings - Fork 122
Expand file tree
/
Copy pathNiven.java
More file actions
34 lines (29 loc) · 637 Bytes
/
Niven.java
File metadata and controls
34 lines (29 loc) · 637 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
/*The program below checks if a number is Niven or not
A number is said to be Niven if it is divisible by the
sum of it's digits
Example: 126
sum of its digits=1+2+6 = 9
and 126 is divisble by 9
hence its Niven
*/
package kshitizjava;
import java.util.*;
public class Niven {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
int num,sum=0,d,p;
System.out.println("Enter A Number");
num=in.nextInt();
p=num;
while(p!=0)
{
d=p%10;
sum+=d;
p/=10;
}
if(num%sum==0)
System.out.println("Its Niven Number");
else
System.out.println("Its Not Niven Number");
}
}