-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathp036.java
64 lines (47 loc) · 1.02 KB
/
p036.java
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import java.util.Arrays;
/**
*
* @author gouravrusiya
*
*/
public class p036 {
public static void main(String[] args) {
// TODO Auto-generated method stub
boolean b,bBinary;
String str ="";
int sum = 0;
for(int i=1;i<=1000000;i++){
b = isPalindrome(i);
if(b){
bBinary = findBinary(i);
if(bBinary){
//System.out.println(i);
sum+=i;
}
}
}
System.out.println(sum);
}
public static boolean isPalindrome(int i){
String str = "" + i;
StringBuilder s = new StringBuilder(str);
StringBuilder sRev = new StringBuilder(str);
sRev.reverse();
if(s.toString().equals(sRev.toString())){
return true;
}
return false;
}
public static boolean findBinary(int i){
String str = "";
str = Integer.toBinaryString(i);
//System.out.println(str);
StringBuilder sb = new StringBuilder(str);
StringBuilder sRev = new StringBuilder(str);
sRev.reverse();
if(sb.toString().equals(sRev.toString())){
return true;
}
return false;
}
}