?? 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 + -