PRO192_-_FA_2022_-_FE_232.webp
hirosi212

PRO192_-_FA_2022_-_FE_232.webp

Multiple choices 25/50
Answer (Choose 1 answer)
Next
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);
1
2
3
4
5
6
7
8
9
10
11
12 13
14
15
16
17
18
19
20 21
22
23 24
25
26
27
28
29
30
31
32
33
34
35
36 37 38 39 40
41
42
43
44
45
46
47 48
49
50

Thông tin

Category
PRO192
Thêm bởi
hirosi212
Ngày thêm
Lượt xem
4,043
Lượt bình luận
8
Rating
0.00 star(s) 0 đánh giá

Share this media

Back
Bên trên Bottom