Skip to content

Instantly share code, notes, and snippets.

@raghavddps2
Created October 5, 2021 14:45
Show Gist options
  • Select an option

  • Save raghavddps2/4795f3cad4fdd04e4df4262e5a161b2a to your computer and use it in GitHub Desktop.

Select an option

Save raghavddps2/4795f3cad4fdd04e4df4262e5a161b2a to your computer and use it in GitHub Desktop.
import java.util.Scanner;
import java.util.*;
public class Main{
public static boolean checkPallindrome(int num){
int actualNum = num;
int reverseNum = 0;
int rem = 0;
while(num >0){
rem = num%10;
reverseNum=(reverseNum*10) + rem;
num /= 10;
}
if(actualNum == reverseNum){
return true;
}
return false;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int size = sc.nextInt();
int arr[] = new int[size];
for(int i=0;i<size;i++){
arr[i] = sc.nextInt();
}
Arrays.sort(arr);
String res = String.valueOf(arr[arr.length-1]) + "-" + String.valueOf(arr[arr.length-2]) + "-";
if(checkPallindrome(arr[arr.length-2])){
res += "palindrome";
}
else{
res += "notPalindrome";
}
System.out.println(res);
sc.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment