Having been going over the documentation, learning more of the subtleties of Java. I am now going over some basic Project-Euler solution code I wrote a little while back. Hoping I can pick up some improvements that show more idiomatic functioning of the language.
Problem-4:
Find the largest palindromic number of the product of two 3-digit numbers.
Solution:
public class Euler_4
{
static int largestPalindrome = 0;
public static void findLargestPalindrome(int m1, int m2)
{
Integer threeDigitProduct = m1 * m2;
if (threeDigitProduct < largestPalindrome) return;
String productStr = threeDigitProduct.toString();
int productStrLen = productStr.length();
int j = productStrLen - 1;
for (int i = 0; i < productStrLen; i++) {
if (productStr.charAt(i) != productStr.charAt(j))
return;
j--;
}
largestPalindrome = threeDigitProduct;
}
public static void main(String[] args)
{
Integer threeDigitProduct;
String productStr;
for (int i = 100; i < 1000; i++)
for (int j = 100; j < 1000; j++)
findLargestPalindrome(i, j);
System.out.println("Answer: " + largestPalindrome);
}
}
Edit: This was exactly what I was hoping for. As basic as things are I knew if I got some responses here it would be far better than me doing it alone through just documentation. Really awesome, thanks!