java中比较大小问题,Arrays.sort()不是可以排序的吗,为什么得不到正确答案
importjava.util.Arrays;publicclassCompare{publicstaticvoidmain(Stringargs[]){Arrays.s...
import java.util.Arrays;
public class Compare{
public static void main(String args[]){
Arrays.sort(args);
System.out.print(args[0]);
for(int i=1;i<args.length;i++){
System.out.print("<"+args[i]);
}
}
}
在虚拟机中以 java Compare num1 num2 num3...的形式输入要比较的数字 展开
public class Compare{
public static void main(String args[]){
Arrays.sort(args);
System.out.print(args[0]);
for(int i=1;i<args.length;i++){
System.out.print("<"+args[i]);
}
}
}
在虚拟机中以 java Compare num1 num2 num3...的形式输入要比较的数字 展开
展开全部
/**
* Sorts the specified array of objects into ascending order, according to
* the {@linkplain Comparable natural ordering}
* of its elements. All elements in the array
* must implement the {@link Comparable} interface. Furthermore, all
* elements in the array must be <i>mutually comparable</i> (that is,
* <tt>e1.compareTo(e2)</tt> must not throw a <tt>ClassCastException</tt>
* for any elements <tt>e1</tt> and <tt>e2</tt> in the array).<p>
*
* This sort is guaranteed to be <i>stable</i>: equal elements will
* not be reordered as a result of the sort.<p>
*
* The sorting algorithm is a modified mergesort (in which the merge is
* omitted if the highest element in the low sublist is less than the
* lowest element in the high sublist). This algorithm offers guaranteed
* n*log(n) performance.
*
* @param a the array to be sorted
* @throws ClassCastException if the array contains elements that are not
* <i>mutually comparable</i> (for example, strings and integers).
*/
public static void sort(Object[] a) {
Object[] aux = (Object[])a.clone();
mergeSort(aux, a, 0, a.length, 0);
}
以上是源码
* Sorts the specified array of objects into ascending order, according to
* the {@linkplain Comparable natural ordering}
* of its elements. All elements in the array
* must implement the {@link Comparable} interface. Furthermore, all
* elements in the array must be <i>mutually comparable</i> (that is,
* <tt>e1.compareTo(e2)</tt> must not throw a <tt>ClassCastException</tt>
* for any elements <tt>e1</tt> and <tt>e2</tt> in the array).<p>
*
* This sort is guaranteed to be <i>stable</i>: equal elements will
* not be reordered as a result of the sort.<p>
*
* The sorting algorithm is a modified mergesort (in which the merge is
* omitted if the highest element in the low sublist is less than the
* lowest element in the high sublist). This algorithm offers guaranteed
* n*log(n) performance.
*
* @param a the array to be sorted
* @throws ClassCastException if the array contains elements that are not
* <i>mutually comparable</i> (for example, strings and integers).
*/
public static void sort(Object[] a) {
Object[] aux = (Object[])a.clone();
mergeSort(aux, a, 0, a.length, 0);
}
以上是源码
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
一般都不用args[]的,主方法的这个东西基本是放着看的,都是空的,你不给他传参数,他的for循环就直接结束了,因为args.length=0了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询