posts - 2,comments - 1,trackbacks - 0
import java.util.*;

class Point implements Comparable{
    
int x;
    
int y;
    
    
public Point(){
        x 
= 0;
        y 
= 0;
    }
    
    
public void setarg( int x, int y ){
        
this.x = x;
        
this.y = y;
    }
    
    
public int getx(){
        
return x;
    }
    
    
public int gety(){
        
return y;
    }
    
    
public int compareTo( Object tmp ){
        Point res 
= ( Point )tmp;
        
        
if( x < res.x || x == res.x && y < res.y ){
            
return -1;
        }
        
else{
            
return 1;
        }
    }
    
}

public class Main{
    
/*
    boolean comparetor( Point a, Point b ){
        if( a.x < b.x | a.x == b.x && a.y < b.y ){
            return true;
        }
        else{
            return false;
        }
    }
    
*/
    
public static void main( String args[] ) throws Exception{
        
        Point [] res 
= new Point[10];
        
        
forint i = 0; i < res.length; i++ ){
            res[i] 
= new Point();
        }
        
        
for(int i = 0; i < res.length; i++){
            res[i].setarg( i 
* i - 10 * i + 250 );
        }
        
        Arrays.sort( res );
        
        
forint i = 0; i < res.length; i++ ){
            System.out.println( res[i].getx() 
+ res[i].gety() );
        }
        
    }
}

posted on 2009-08-22 21:55 Huicpc217 阅读(1282) 评论(0)  编辑 收藏 引用 所属分类: JAVA模板

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理