PRO192_-_C2_-_RE_-_SU_2023_558.webp
N

PRO192_-_C2_-_RE_-_SU_2023_558.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(price-x.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",5));
t.add(new Pen("D", 7));
t.add(new Pen("C",4));
t.add(new Pen("A",6));
Collections.sort(t);
for(Pen x: t) System.out.print(x);System.out.println();
A. (A,6) (B,3) (C,4) (C,5) (D,7)
Β. (A,6) (B,3) (C,5) (C,4) (D,7)
Et 45

Thông tin

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

Image metadata

Filename
PRO192_-_C2_-_RE_-_SU_2023_558.webp
File size
67.7 KB
Dimensions
1542px x 690px

Share this media

Back
Bên trên Bottom