📄 usemypoint.java
字号:
/*
* Created on 2005-10-20
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package chap06;
/**
* @author Administrator
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
class MyPoint implements Comparable{
int x;
int y;
public MyPoint(int x,int y){
this.x = x;
this.y = y;
}
public int compareTo(Object o){
int n = ((MyPoint)o).x;
if(x > n)
return 1;
else if (x<n)
return -1;
else
return 0;
}
}
class SortPoint {
public MyPoint[] data = null;
public SortPoint(MyPoint[] value) {
data = value;
}
public void sort() {
java.util.Arrays.sort(data);
}
}
public class UseMyPoint {
public static void main(String[] args) {
MyPoint[] arr = new MyPoint[10];
for(int i=0;i<arr.length;i++){
arr[i] = new MyPoint((int)(Math.random()*10),(int)(Math.random()*10));
System.out.println("("+arr[i].x +", "+ arr[i].y+")");
}
SortPoint sortPoint = new SortPoint(arr);
sortPoint.sort();
System.out.println("After order:");
for(int i=0;i<arr.length;i++){
System.out.println("("+arr[i].x +", "+ arr[i].y+")");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -