Advertisement
JeffGrigg

Mystery Program with Swap

Nov 27th, 2018
555
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.52 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.stream.Collectors;
  3.  
  4. public class Driver {
  5.     public static void main(String[] args) {
  6.         int[] x = {3, 1, 5, 2, 4};
  7.         int a = 0;
  8.         for (int index = 0; index < x.length - 1; index++) {
  9.             if (x[index] > x[index + 1]) {
  10.                 a = x[index];
  11.                 x[index] = x[index + 1];
  12.                 x[index + 1] = a;
  13.             }
  14.         }
  15.         System.out.println("x = " + Arrays.stream(x).boxed().collect(Collectors.toList()));
  16.     }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement