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

前端 未结 17 1019
天涯浪人
天涯浪人 2021-02-02 04:27
package testing.project;

public class PalindromeThreeDigits {

    public static void main(String[] args) {
        int value = 0;
        for(int i = 100;i <=999;i+         


        
17条回答
  •  滥情空心
    2021-02-02 05:22

    I tried the solution by Tobin joy and vickyhacks and both of them produce the result 580085 which is wrong here is my solution, though very clumsy:

    import java.util.*;
    class ProjEu4
    {
    
    public static void main(String [] args) throws Exception
    {
        int n=997;
        ArrayList al=new ArrayList();
        outerloop:
        while(n>100){
        int k=reverse(n);
        int fin=n*1000+k;
                al=findfactors(fin);
        if(al.size()>=2)
            {
                for(int i=0;i findfactors(int fin)
    {
        ArrayList al=new ArrayList();
        for(int i=100;i<=999;i++)
        {
            if(fin%i==0)
                al.add(i);
        }
        return al;
    }
    private static int reverse(int number)
    {
        int reverse = 0;
        while(number != 0){
            reverse = (reverse*10)+(number%10);
            number = number/10;
        }
        return reverse;
    }
    }
    

提交回复
热议问题