Guest User

Untitled

a guest
Dec 14th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package codingquestionreview;
  6.  
  7. /**
  8.  *
  9.  * @author Beth Irvine
  10.  */
  11. public class CodingQuestionReview {
  12.  
  13.     /**
  14.      * @param args the command line arguments
  15.      */
  16.     public static void main(String[] args) {
  17.         // TODO code application logic here
  18.  
  19.         int[] array = new int[]{1, 2, 3, 4, 5, 6};
  20.  
  21.         System.out.println("The array pre reverse: ");
  22.         for (int i = 0; i < array.length; i++) {
  23.             System.out.println(array[i]);
  24.         }
  25.  
  26.         int temp;
  27.         int left = 0;
  28.         int right = array.length - 1;
  29.         while (left < right) {
  30.  
  31.             temp = array[left];
  32.             array[left] = array[right];
  33.             array[right] = temp;
  34.             left++;
  35.             right--;
  36.         }
  37.         System.out.println("The array post reverse:");
  38.         for (int j = 0; j < array.length; j++) {
  39.             System.out.println(array[j]);
  40.  
  41.         }
  42.  
  43.     }
  44. }
Add Comment
Please, Sign In to add comment