Advertisement
TsetsoP

UPR12

Feb 10th, 2021
1,189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.17 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class upr12 {
  4.  
  5.     public static void main(String[] args) {
  6.         int [] array = {2,3,6,7,88,3,1};
  7.         int [] array2 = {2,4,6,6,18,9,51};
  8.         System.out.println(Arrays.toString(array));
  9.         reverseArr(array);
  10.         System.out.println(Arrays.toString(array));
  11.         System.out.println(check1(array));
  12.         System.out.println(check1(array2));
  13.  
  14.     }
  15.    
  16.     public static void reverseArr(int[] array) {
  17.         for(int i = 0; i < array.length / 2 ; i++ ) {
  18.             int I = array[i];
  19.             array [i] = array [array.length - 1 -i];
  20.             array [array.length - 1 - i] = I;
  21.             }
  22.         }
  23.    
  24.     public static void printReverseArr(int[] array) {
  25.         for(int i = array.length - 1 ; i>= 0; i--) {
  26.             System.out.print(array[i] + " ");
  27.             }
  28.         System.out.println();
  29.         }
  30.    
  31.     public static boolean check1(int[] array) {
  32.         boolean check = true;
  33.         for (int i = 0; i<array.length /2; i++) {
  34.             if(array[i] != array[array.length - 1 - i]) {
  35.                 check = false;
  36.                 break;
  37.                 }
  38.             }
  39.         return check;
  40.        
  41.     }
  42.     public static void check2(int[] array) {
  43.         boolean check = true;
  44.         for (int i = 0; i<array.length /2; i++) {
  45.             if(array[i] != array[array.length - 1 - i]) {
  46.                 check = false;
  47.                 }
  48.             }
  49.    
  50.     }
  51.  
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement