Skip to main content
Code Review

Return to Question

improved title, add link and description of problem
Source Link
Phrancis
  • 20.5k
  • 6
  • 69
  • 155

How can I make my code for Project Euler #4 more efficient and cleaner?: Largest palindrome product

How can I make my code for Project Euler #4 more efficient and cleaner?

Project Euler #4: Largest palindrome product :

A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 ×ばつ 99.

Find the largest palindrome made from the product of two 3-digit numbers.

public class LargestPalindromeProduct {
 public static void main(String[] args) {
 
 int product = 0;
 int largest = 0;
 for (int first = 1; first < 1000; first++) {
 for(int second = 1; second < 1000; second++) {
 product = first * second;
 if ((product / 100000) % 10 == product % 10 && product / 10000 % 10 == product / 10 % 10 && product / 1000 % 10 == product / 100 % 10) {
 //System.out.println(product);
 if (product > largest) {
 largest = product;
 
 
 } 
 }
 
 }
 }
 System.out.println(largest); 
 }
}

How can I make my code for Project Euler #4 more efficient and cleaner?

public class LargestPalindromeProduct {
 public static void main(String[] args) {
 
 int product = 0;
 int largest = 0;
 for (int first = 1; first < 1000; first++) {
 for(int second = 1; second < 1000; second++) {
 product = first * second;
 if ((product / 100000) % 10 == product % 10 && product / 10000 % 10 == product / 10 % 10 && product / 1000 % 10 == product / 100 % 10) {
 //System.out.println(product);
 if (product > largest) {
 largest = product;
 
 
 } 
 }
 
 }
 }
 System.out.println(largest); 
 }
}

Project Euler #4: Largest palindrome product

How can I make my code for Project Euler #4 more efficient and cleaner?

Project Euler #4: Largest palindrome product :

A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 ×ばつ 99.

Find the largest palindrome made from the product of two 3-digit numbers.

public class LargestPalindromeProduct {
 public static void main(String[] args) {
 
 int product = 0;
 int largest = 0;
 for (int first = 1; first < 1000; first++) {
 for(int second = 1; second < 1000; second++) {
 product = first * second;
 if ((product / 100000) % 10 == product % 10 && product / 10000 % 10 == product / 10 % 10 && product / 1000 % 10 == product / 100 % 10) {
 //System.out.println(product);
 if (product > largest) {
 largest = product;
 
 
 } 
 }
 
 }
 }
 System.out.println(largest); 
 }
}
Source Link

How can I make my code for Project Euler #4 more efficient and cleaner?

public class LargestPalindromeProduct {
 public static void main(String[] args) {
 
 int product = 0;
 int largest = 0;
 for (int first = 1; first < 1000; first++) {
 for(int second = 1; second < 1000; second++) {
 product = first * second;
 if ((product / 100000) % 10 == product % 10 && product / 10000 % 10 == product / 10 % 10 && product / 1000 % 10 == product / 100 % 10) {
 //System.out.println(product);
 if (product > largest) {
 largest = product;
 
 
 } 
 }
 
 }
 }
 System.out.println(largest); 
 }
}
lang-java

AltStyle によって変換されたページ (->オリジナル) /