SHARE
TWEET

Untitled

a guest Jul 19th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class arrayReverse {
  2.      
  3.     /* function that reverses array and stores it  
  4.        in another array*/
  5.     static void reverse(int a[], int n)
  6.     {
  7.         int[] b = new int[n];
  8.         int j = n;
  9.         for (int i = 0; i < n; i++) {
  10.             b[j - 1] = a[i];
  11.             j = j - 1;
  12.         }
  13.  
  14.         /*printing the reversed array*/
  15.         System.out.println("Reversed array is: \n");
  16.         for (int k = 0; k < n; k++) {
  17.             System.out.println(b[k]);
  18.         }
  19.     }
  20.  
  21.     public static void main(String[] args)
  22.     {
  23.         int [] arr = {1, 2, 3};
  24.         reverse(arr, arr.length);
  25.     }
  26. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top