Advertisement
Guest User

Untitled

a guest
May 25th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. import java.util.LinkedList;
  2. import java.util.Scanner;
  3.  
  4. public class Palindrom {
  5.  
  6. public static void main(String[] args) {
  7. // TODO Auto-generated method stub
  8.  
  9.  
  10. LinkedList <Integer> lista = new LinkedList<>();
  11. Scanner sc = new Scanner(System.in);
  12. int palin = 0;
  13. String n = sc.nextLine();
  14. String l = sc.nextLine();
  15. String[] a = l.split(" ");
  16. int brojac = 0;
  17.  
  18. for(int i = 0 ; i<Integer.parseInt(n) ; i++)
  19. {
  20. lista.add(Integer.parseInt(a[i]));
  21. }
  22.  
  23. if(lista.size() == 1)
  24. {
  25. palin = 1;
  26. }
  27.  
  28. else
  29. {
  30. while(brojac < lista.size()/2)
  31. {
  32.  
  33. if(lista.get(brojac) == lista.get(lista.size()-1-brojac))
  34. {
  35. palin = 1;
  36. }
  37. else
  38. {
  39. palin = -1;
  40. break;
  41. }
  42. brojac++;
  43. }
  44. }
  45.  
  46.  
  47. System.out.print(palin);
  48. sc.close();
  49. }
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement