HackerRank - Cracking the Code Interview - Sorting: Bubble Sort

Here's my Java solution for HackerRank and Cracking the Code Interview's Sorting: Bubble Sort problem.

import java.io.*;  
import java.util.*;

public class Solution {

    private static void work(int[] a) {
        int swaps = 0;

        int n = a.length;

        if (n == 0) return;

        for (int i = 0; i < n; i++) {
            // Track number of elements swapped during a single array traversal
            int numberOfSwaps = 0;

            for (int j = 0; j < n - 1; j++) {
                // Swap adjacent elements if they are in decreasing order
                if (a[j] > a[j + 1]) {
                    swap(a, j, j + 1);
                    numberOfSwaps++;
                    swaps++;
                }
            }

            // If no elements were swapped during a traversal, array is sorted
            if (numberOfSwaps == 0) {
                break;
            }
        }

        System.out.println("Array is sorted in " + swaps + " swaps.");
        System.out.println("First Element: " + a[0]);
        System.out.println("Last Element: " + a[n - 1]);
    }

    private static void swap(int[] a, int from, int to) {
        int newFrom = a[to];
        int newTo = a[from];

        a[from] = newFrom;
        a[to] = newTo;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int a[] = new int[n];
        for(int a_i=0; a_i < n; a_i++){
            a[a_i] = in.nextInt();
        }
        work(a);
    }
}