第八章第二十六题(行排序)(row sorting)
-
*8.26(行排序)用下面的方法实现一个二维数组中的行排序,返回一个新的数组,并且原数组保持不变。
public static double[][] sortRows(double[][] m)
编写一个测试程序,提示用户输入一个3×3的double类型值的矩阵。显示一个新的每行排好序的矩阵,下面是一个运行示例:
Enter a 3-by-3 matrix row by row:
0.15 0.875 0.375
0.55 0.005 0.225
0.30 0.12 0.4
The row-sorted array is
0.15 0.375 0.875
0.005 0.225 0.55
0.12 0.3 0.4
*8.26(row sorting)Use the following method to sort rows in a two-dimensional array, return a new array, and the original array remains unchanged.
public static double[][] sortRows(double[][] m)
Write a test program to prompt the user to input a matrix of 3 × 3 double type values. A good example of running a new row is shown below:
Enter a 3-by-3 matrix row by row:
0.15 0.875 0.375
0.55 0.005 0.225
0.30 0.12 0.4
The row-sorted array is
0.15 0.375 0.875
0.005 0.225 0.55
0.12 0.3 0.4 -
参考代码:
package chapter08; import java.util.Scanner; public class Code_26 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println