Skip to main content
deleted 205 characters in body; edited tags
Source Link
toolic
  • 16.4k
  • 6
  • 29
  • 221

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!

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!

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
Source Link
tijko
  • 782
  • 1
  • 5
  • 13

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!

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);
    }
}

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!

Became Hot Network Question
Title improved, original problem description properly formatted, tags edited
Source Link

Basic Java Euler Solution- Largest Palindrome Product in Java

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);
    }
}

Straight-forward problem - Find the largest palindromic number of the product of two 3-digit numbers.

Basic Java Euler Solution

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:

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);
    }
}

Straight-forward problem - Find the largest palindromic number of the product of two 3-digit numbers.

Euler - Largest Palindrome Product in Java

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);
    }
}
edited tags
Link
toolic
  • 16.4k
  • 6
  • 29
  • 221
Loading
Source Link
tijko
  • 782
  • 1
  • 5
  • 13
Loading