zoukankan      html  css  js  c++  java
  • 金银铜排序程序

    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);
                
           

                  }
        }
       
    }

  • 相关阅读:
    XML&nbsp; XmlDocument
    程序集报错
    程序打开网页
    写入文件txt
    读取文件txt
    MSM8953中Android系统添加启动脚本.rc文件
    SELinux基础知识
    嵌入式Linux设备查看USB相关信息
    Linux内核态文件读写相关函数API
    C语言中sscanf()函数相关用法
  • 原文地址:https://www.cnblogs.com/hansongjiang/p/3784776.html
Copyright © 2011-2022 走看看