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

Java sorting double array example sharing

高洛峰
Release: 2017-01-23 16:09:26
Original
2541 people have browsed it

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]);
   }
  }
 }
}
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template