Die Aufgabe ist es, dass zwei dreistellige zahlen multipliziert werden sollen und herausgefunden werden soll, welches das größte Palindrom Produkt ist. Bei mir wird aus irgend einem Grund 580085 ausgegeben, obwohl es 906609 sein sollte.
[CODE lang="java" title="Palindrome finden von xxx * xxx"]package ProjectEuler4;
public class Main {
public static void main(String[] args) {
System.out.println(findBiggestPalindromeNum());
}
public static int findBiggestPalindromeNum() {
int num = 0;
for (int i = 100; i < 1000 ; i++) {
for (int j = 100; j < 1000; j++) {
if (isPalindromeNum(i, j)) {
num = i * j;
if (num < i * j) {
num = i * j;
}
}
}
}
return num;
}
public static boolean isPalindromeNum(int f, int s) {
String a = String.valueOf(f * s);
int[] ascii = new int[]{48, 49, 50, 51, 52, 53, 54, 55, 56, 57};
int[] nums = new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int[] arr = new int[a.length()];
for (int i = 0; i < a.length(); i++) {
for (int j : nums) {
if (a.charAt(i) == ascii[j]) {
arr = nums[j];
}
}
}
if (a.length() == 5 && arr[0] == arr[4] && arr[1] == arr[3]) {
return true;
}
return a.length() == 6 && arr[0] == arr[5] && arr[1] == arr[4] && arr[2] == arr[3];
}
}
[/CODE]
[CODE lang="java" title="Palindrome finden von xxx * xxx"]package ProjectEuler4;
public class Main {
public static void main(String[] args) {
System.out.println(findBiggestPalindromeNum());
}
public static int findBiggestPalindromeNum() {
int num = 0;
for (int i = 100; i < 1000 ; i++) {
for (int j = 100; j < 1000; j++) {
if (isPalindromeNum(i, j)) {
num = i * j;
if (num < i * j) {
num = i * j;
}
}
}
}
return num;
}
public static boolean isPalindromeNum(int f, int s) {
String a = String.valueOf(f * s);
int[] ascii = new int[]{48, 49, 50, 51, 52, 53, 54, 55, 56, 57};
int[] nums = new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int[] arr = new int[a.length()];
for (int i = 0; i < a.length(); i++) {
for (int j : nums) {
if (a.charAt(i) == ascii[j]) {
arr = nums[j];
}
}
}
if (a.length() == 5 && arr[0] == arr[4] && arr[1] == arr[3]) {
return true;
}
return a.length() == 6 && arr[0] == arr[5] && arr[1] == arr[4] && arr[2] == arr[3];
}
}
[/CODE]