JeffGrigg icon

Mystery Program with Swap

JeffGrigg | PRO | 11/27/18 12:09:04 PM UTC | 0 ⭐ | 939 👁️ | Never ⏰ | []
Java 5 |

0 B

|

None

|

0 👍

/

0 👎

import java.util.Arrays;
import java.util.stream.Collectors;
 
public class Driver {
    public static void main(String[] args) {
        int[] x = {3, 1, 5, 2, 4};
        int a = 0;
        for (int index = 0; index < x.length - 1; index++) {
            if (x[index] > x[index + 1]) {
                a = x[index];
                x[index] = x[index + 1];
                x[index + 1] = a;
            }
        }
        System.out.println("x = " + Arrays.stream(x).boxed().collect(Collectors.toList()));
    }
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎