Created
July 18, 2017 04:14
-
-
Save murphym18/3d113e7759e88ad1318b4701c1df029a to your computer and use it in GitHub Desktop.
special196 created by murphym18 - https://repl.it/J62R/6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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