/*********************************************************************************
* (Shuffle rows) Write a method that shuffles the rows in a two-dimensional int  *
* array using the following header:                                              *
*                                                                                *
* public static void shuffle(int[][] m)                                          *
*                                                                                *
* Write a test program that shuffles the following matrix:                       *
*                                                                                *
* int[][] m = {{1, 2}, {3, 4}, {5, 6}, {7, 8}, {9, 10}};                         *
*********************************************************************************/
public class Exercise_08_18 {
	/** Main method */
	public static void main(String[] args) {
		int[][] m = {{1, 2}, {3, 4}, {5, 6}, {7, 8}, {9, 10}};
		shuffle(m);
		for (int i = 0; i < m.length; i++) {
			for (int j = 0; j < m[i].length; j++) {
				System.out.print(m[i][j] + " ");
			}
			System.out.println();
		}
	}

	public static void shuffle(int[][] m) {
		int[] temp = new int[2];
		for (int i = 0; i < m.length; i++) {
			int i1 = (int)(Math.random() * m.length);

			temp[0] = m[i][0];
			temp[1] = m[i][1];
			m[i][0] = m[i1][0];
			m[i][1] = m[i1][1];
			m[i1][0] = temp[0];
			m[i1][1] = temp[1];
		}
	}
}
@@ -911,24 +911,47 @@
 g%5B%5D args) %7B%0A
+%09%09// Initialize matrix%0A
 %09%09int%5B%5D%5B%5D m 
@@ -999,21 +999,92 @@
 %7D%7D;%0A
-%09%09shuffle(m);
+%0A%09%09// Randomly shuffle the rows in the matrix%0A%09%09shuffle(m);%0A%0A%09%09// Display the matrix
 %0A%09%09f
@@ -1237,16 +1237,81 @@
 %09%09%7D%0A%09%7D%0A%0A
+%09/** shuffle shuffles the rows in a two-dimensional int array */%0A
 %09public 
@@ -1370,16 +1370,17 @@
 int%5B2%5D;%0A
+%0A
 %09%09for (i
@@ -1410,16 +1410,44 @@
  i++) %7B%0A
+%09%09%09// Generate random index%0A
 %09%09%09int i
@@ -1484,16 +1484,45 @@
 ngth);%0A%0A
+%09%09%09// Swap row i with row i1%0A
 %09%09%09temp%5B

Modify comments Ex 8.18