import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; public class 绝对值排序 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc=new Scanner(System.in); while (sc.hasNext()) { int n=sc.nextInt(); if (n==0) { break; } Integer A[]=new Integer[n]; //输入 for (int i = 0; i < A.length; i++) { A[i]=sc.nextInt(); } Arrays.sort(A,new Comparator<Integer>() { public int compare(Integer a,Integer b){ return Math.abs(b)-Math.abs(a); }; }); for (Integer i : A) { System.out.print(i+" "); } System.out.println(); } } }
解题思路:
自定义排序鬼咋,实现Comparator方法
注意事项:
参考代码:
0.0分
1 人评分
字符串输入输出函数 (Java代码)浏览:1439 |
简单的a+b (C语言代码)浏览:573 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:1157 |
Wu-求圆的面积 (C++代码)浏览:1888 |
核桃的数量 (C语言代码)浏览:872 |
字符串的输入输出处理 (C语言代码)浏览:989 |
1134题解(求分析)浏览:726 |
发工资咯 (C语言代码)浏览:792 |
C语言程序设计教程(第三版)课后习题7.4 (C语言代码)浏览:3242 |
简单的a+b (C语言代码)浏览:602 |