java数组 要求:编写合并排序方法 主方法调用 打印合并排序后方法?
1个回答
展开全部
package test; import java.util.Arrays;import java.util.Comparator; public class JButtonTest{ public static void main ( String[] args ) { int[] arr1 = { 3, 1, 23 }; int[] arr2 = { 27, 7, 2 }; String temp = Arrays.toString (arr1) + Arrays.toString (arr2); temp = temp.replaceAll ("\\]\\[", ",").replaceAll ("\\s", "").replaceAll ("[\\[\\]]", ""); String[] result = temp.split ("\\,"); System.out.println (Arrays.toString (result)); Arrays.sort (result, new Comparator<String> () { @Override public int compare ( String o1, String o2 ) { int a = Integer.parseInt (o1), b = Integer.parseInt (o2); if (a > b) { return 1; } else if (a < b) { return -1; } else { return 0; } } }); System.out.println (Arrays.toString (result)); }}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询