首页 > 其他 > 详细

金银铜排序程序

时间:2014-06-13 15:37:42      阅读:502      评论:0      收藏:0      [点我收藏+]

package 单例模式;

import java.awt.List;
import java.util.ArrayList;
import java.util.Arrays;

public class Country implements Comparable<Country>
{
    int jin;
    int yin;
    int tong;
    String name;
   

    public int compareTo(Country o) {
        // TODO Auto-generated method stub
        if(this.jin<o.jin)
        {
            return 1;
           
        }
        else if(this.jin>o.jin )
        {
           
            return -1;
           
        }
        else
        {
           
           
           
            if(this.yin<o.yin)
            {
                return 1;
               
            }
            else if(this.yin>o.yin)
            {
               
                return -1;
               
            }
            else
            {
               
               
                if(this.tong<o.tong)
                {
                    return 1;
                   
                }
                else if(this.tong>o.tong)
                {
                   
                    return -1;
                   
                }
                else
                {
                    return this.name.compareTo(o.name );
                   
                }
               
            }
           
           
           
        }
       
    }
    public Country(int jin, int yin, int tong, String name) {
        super();
        this.jin = jin;
        this.yin = yin;
        this.tong = tong;
        this.name = name;
    }
   
    public static void main(String[] args) {
        ArrayList<Country> array=new ArrayList<Country>();
       
       
        Country c[]=new Country[4];
        
       
         c[0]=new Country(32,23,10,"China");
         c[1]=new Country(32,23,10,"Coo");
         c[2]=new Country(20,13,23,"Jpan");
         c[3]=new Country(20,12,34,"lisi");
         Arrays.sort(c);
         for(int i=0;i<4;i++)
         {
             System.out.println(c[i].name +"--"+c[i].jin+"--"+c[i].tong+"--"+c[i].tong);
            
       

              }
    }
   
}

金银铜排序程序,布布扣,bubuko.com

金银铜排序程序

原文:http://www.cnblogs.com/hansongjiang/p/3784776.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!