-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPaliBase.java
More file actions
37 lines (29 loc) · 973 Bytes
/
PaliBase.java
File metadata and controls
37 lines (29 loc) · 973 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
package TestSample;
import java.util.List;
public class PaliBase {
public static void main(String[] args) {
int value; // int value of decimal converted to the specified base
List<Integer> valueBase; // list value of decimal converted to the
// specified base
Pali p = new Pali();
System.out.println("Decimal\t" + "Smallest Base for Palindrome");
// loop to display the first 1000 positive decimal numbers
// with the smallest base in which they are palindromes
for (int i = 1; i <= 1000; i++) {
System.out.print(i + "\t");
for (int j = 2; j <= i + 2; j++) {
Base b = new Base(j);
// calculate the value of i in base j
b.decToNBase(i);
valueBase = b.revNBase();
// convert list to int
value = b.convertToInt(valueBase);
// check for the smallest base which has a palindrome
if (p.checkPali(value) == true) {
System.out.println(j);
break;
}
}
}
}
}