-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNiven.java
More file actions
48 lines (40 loc) · 1.48 KB
/
Niven.java
File metadata and controls
48 lines (40 loc) · 1.48 KB
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
import java.util.*;
import jdk.internal.jimage.decompressor.ZipDecompressorFactory;
class Niven {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
while (true) {
System.out.println("Enter base of the number");
int b = sc.nextInt();
if (b <= 36) {
while (true) {
System.out.println("Enter any number");
String n = sc.next();
boolean valid = true;
for (int x = n; x != 0; x /= 10) {
// CHECK VALIDITY OF numerals of n with the base b accordingly like A to Z
}
if (!valid) {
System.out.println("Invalid Number");
continue;
}
int s = 0;
for (int x = n; x != 0; x /= 10) {
int d = x % 10;
s += d;
}
if (convert(n) % convert(s) == 0) {
System.out.println(n+" is a Niven Number");
}
else{
System.out.println(n+" is not a Niven Number");
}
}
}
else{
System.out.println("Invalid Input");
continue;
}
}
}
}