Skip to content

Instantly share code, notes, and snippets.

@murphym18
Created July 18, 2017 04:14
Show Gist options
  • Save murphym18/3d113e7759e88ad1318b4701c1df029a to your computer and use it in GitHub Desktop.
Save murphym18/3d113e7759e88ad1318b4701c1df029a to your computer and use it in GitHub Desktop.
special196 created by murphym18 - https://repl.it/J62R/6
import java.math.BigDecimal;
public class Main{
public static void main(String[] args) {
BigDecimal a = new BigDecimal(89);
find(a);
}
public static void find(BigDecimal f) {
while(!checkNumber(f)) {
BigDecimal r = getReverse(f);
BigDecimal tmp = f.add(r);
System.out.println(f.toString() + " + " + r.toString() + " = " + tmp.toString());
f = tmp;
}
}
public static BigDecimal getReverse(BigDecimal x) {
return new BigDecimal(reverseString(x.toString()));
}
public static boolean checkNumber(BigDecimal x) {
String forward = x.toString();
String backward = reverseString(forward);
return forward.equals(backward);
}
public static String reverseString(String s) {
StringBuffer b = new StringBuffer(s);
return b.reverse().toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment