Home  >  Article  >  Java  >  Java sorting double array example sharing

Java sorting double array example sharing

高洛峰
高洛峰Original
2017-01-23 16:09:262514browse

package airthmatic;
public class demo10 {

 public static void main(String[] args) {

  double n[]={9,1.2,5,3.2,1.1};
  orderNum(n); 
 }

 /**
  * double 和 int 数字排序
  * @param n
  */
 public static void orderNum(double []n){

  for(int i=0;i<n.length-1;i++){
   for(int j=0;j<n.length-1-i;j++){
    double temp=0;
    if(n[j]>n[j+1]){
     temp=n[j+1];
     n[j+1]=n[j];
     n[j]=temp;
    }
   }
  }
  /**
   * 这里是过滤掉整数的double类型
   */
  for(int i=0;i<n.length;i++){
   int temp=(int)n[i];
   if(n[i]%temp==0){
    System.out.println(temp);
   }else{
    System.out.println(n[i]);
   }
  }
 }
}

For more java examples of sorting double arrays and related articles, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn