Last active
September 1, 2015 20:20
-
-
Save SirEdvin/7ee5f0ddc26c7c0fb33d to your computer and use it in GitHub Desktop.
Palindrome task
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Optional; | |
/** | |
* Created by siredvin on 01.09.15. | |
* | |
* @author siredvin | |
*/ | |
public class SimpleAnswer { | |
public static void main(String[] args) { | |
int max = 999*999; | |
boolean wasFound = false; | |
for (int palindromePart = 999; palindromePart > 99; palindromePart--) { | |
int palindrome = palindromePart*1000 + (palindromePart % 10)*100 + (palindromePart %100 /10)*10 + palindromePart /100; | |
if (palindrome>max){ | |
continue; | |
} | |
int sqrt = (int) (Math.floor(Math.sqrt(palindrome)) - 1); | |
for (int divider = 999; divider>sqrt;divider--){ | |
if (palindrome % divider == 0 && (palindrome / divider) / 1000 == 0){ | |
System.out.printf("palindrome %d = %d * %d",palindrome,divider, palindrome/divider); | |
wasFound = true; | |
break; | |
} | |
} | |
if (wasFound){ | |
break; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment