Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1. package garbage;
  2.  
  3. public class Garbage {
  4.  
  5.     public static void main(String[] args) {
  6.        
  7.         int[] array = {1, 1, 8, 5, 3, 7, 4, 3, 2, 4, 7, 3, 5, 9, 0};
  8.        
  9.         int result = 0;
  10.         int number;
  11.         int first;
  12.         int last;
  13.        
  14.         for (int i=0; i<array.length-2; i++){
  15.             for (int j=array.length-1; j>i; j--){
  16.                 number = 0;
  17.                 first = i;
  18.                 last = j;
  19.                 while (first<array.length && last>=0 && array[first]==array[last]){
  20.                     number++;
  21.                     first++;
  22.                     last--;
  23.                 }
  24.                 if (number>result){
  25.                     result = number;
  26.                 }
  27.             }
  28.         }
  29.         System.out.println("Result: " + result);
  30.     }
  31.    
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement