Created
June 30, 2016 20:47
-
-
Save Yurlov/92ce192a8619be1a07f482ef23f2f9cf to your computer and use it in GitHub Desktop.
Prog.kiev.ua
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
public class PalindromSample { | |
public static void main(String[] args) { | |
Scanner in = new Scanner(System.in); | |
int[] myArray = new int[10]; | |
arrayFiller(in, myArray); | |
getPalindromNumber(myArray); | |
} | |
private static boolean isPalindromNumber(int number) { | |
String firstPart = Integer.toString(number); | |
String secondPart = ""; | |
for (int num = firstPart.length()-1; num>=0; num--) | |
secondPart += firstPart.charAt(num); | |
return firstPart.equals(secondPart); | |
} | |
private static void getPalindromNumber(int array[]) { | |
int tmp = 0; | |
for (int elem : array) { | |
if (isPalindromNumber(elem)) { | |
tmp = elem; | |
} | |
} | |
System.out.println("Palindrom-number is :" + tmp); | |
} | |
private static void arrayFiller(Scanner in, int[] array) { | |
for (int i = 0; i < array.length; i++) { | |
array[i] = in.nextInt(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment