码迷,mamicode.com
首页 > 其他好文 > 详细

金银铜排序程序

时间:2014-06-13 15:38:12      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:class   java   com   string   name   for   

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

金银铜排序程序

标签:class   java   com   string   name   for   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!