国开 / 面向对象程序设计
class ABC {
int a,b;
public ABC(int a, int b) {this.a=a; this.b=b;}
public int compareTo(ABC x) {return a*b-x.a*x.b;}
}
public class XXK5 {
public static void main(String[] args) {
int [][]d={{3,8},{4,6},{5,6},{2,9},{6,7},{5,8}};
ABC []ar=new ABC[d.length];
int i,k=0;
for(i=0; i
ar[i]=new ABC(d[i][0],d[i][1]);
for(i=1; i
if(ar[i].compareTo(ar[k])>0) k=i;
System.out.println("k="+k);
}
}
k=4
k=10
int a,b;
public ABC(int a, int b) {this.a=a; this.b=b;}
public int compareTo(ABC x) {return a*b-x.a*x.b;}
}
public class XXK5 {
public static void main(String[] args) {
int [][]d={{3,8},{4,6},{5,6},{2,9},{6,7},{5,8}};
ABC []ar=new ABC[d.length];
int i,k=0;
for(i=0; i
ar[i]=new ABC(d[i][0],d[i][1]);
for(i=1; i
if(ar[i].compareTo(ar[k])>0) k=i;
System.out.println("k="+k);
}
}
k=4
k=10
参考答案:
佳题速递: