MKT101_-_SP_2023_-_FE_77.webp
Đ

MKT101_-_SP_2023_-_FE_77.webp

(Choose 1 answer)
What is the output of the following program?
import java.util.*;
class Pen implements Comparable<Pen> {
String color; int price;
Pen(String color, int price) { this.color=color; this.price=price; }
public String toString() { return("("+color+","+price+") "); }
public int compareTo(Pen x) { int k = color.compareTo(x.color);
if(k!=0) return(-k);
return(x.price - price);
}
}
public class Main {
public static void main(String[] args) {
List<Pen> t = new ArrayList<>();
t.add(new Pen("B",3));
t.add(new Pen("C",4));
t.add(new Pen("D",7));
t.add(new Pen("C",5));t.add(new Pen("A",6));
Collections.sort(t);
Ext
24
  • Like
Reactions: ha hong nhu y

Thông tin

Category
MKT101
Thêm bởi
Đức Long
Ngày thêm
Lượt xem
1,706
Lượt bình luận
6
Rating
0.00 star(s) 0 đánh giá

Share this media

Back
Bên trên Bottom