I am trying to figure out "what 5-digit number when multiplied by 4 gives you its reverse?" using this code but I get error: Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 5 at java.lang.String.charAt(String.java:658) at Digits.main(Digits.java:12)
public class Digits{
public static void main(String[] args) {
int n = 0;
int b = 0;
String number = Integer.toString(n);
String backwards = Integer.toString(b);
for (int x = 9999; x < 100000 ; x++ ) {
n = x;
b = x *4;
if (number.charAt(0) == backwards.charAt(5 )&& number.charAt(1) == backwards.charAt(4)
&& number.charAt(2) == backwards.charAt(3) && number.charAt(3) == backwards.charAt(2)
&& number.charAt(4) == backwards.charAt(1) && number.charAt(5) == backwards.charAt(0)) {
System.out.println(n);
break;
}
}
Any help would be grealy appreciated