Advertisement
Petra_Abrasheva_185

Sort from behind and check what is longer

Feb 8th, 2021
1,019
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1. import java.util.Arrays;
  2. //import java.util.Scanner;
  3.  
  4. public class Main {//sort from behind
  5.     public static void reverseArray(int[] arr1 ){
  6.         for (int i = 0; i < arr1.length/2; i++) {
  7.         int item = arr1[i];
  8.         arr1[i]=arr1[arr1.length-1-i];
  9.         arr1[arr1.length-1-i] = item;
  10.         }
  11.  
  12.  
  13.     }
  14.  
  15.     public static void main (String [] Args){
  16.         int[] arr1 = {1,2,3,4,5};
  17.         int[] arr2 = {2,7,4,9};
  18.         if (arr1.length==arr2.length){//check what is longer
  19.             System.out.println("yes");
  20.         }else{
  21.             System.out.println("no");
  22.         }
  23.         System.out.println(Arrays.toString(arr1));
  24.         reverseArray(arr1);
  25.         System.out.println(Arrays.toString(arr1));
  26.     }
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement