我有这个输出,我想确定价格最高的计算机
Name Capacity Price
----- ------- -----
Computer 1 Dell 170 292.30
Computer 2 HP 94 452.30
Computer 3 Compaq 167 933.30
Computer 4 Toshiba 162 1171.30
Computer 5 Dell 189 1550.30
Computer 6 HP 53 2027.30
Computer 7 Apple 29 2288.30
Computer 8 Dell 48 2542.30
Computer 9 Dell 128 2700.30
Computer 10 Lenovo 171 2828.30
the computer with max price is :
Lenovo 171 2828.30
我得到了代码,但它打印了整行,我只想要那台计算机的名称 这是代码
System.out.println("the computer with max price is :");
SortByPrice(list);
int k = list.length;
list[k-1].printComputer();
我想将该行的第一个索引作为计算机的名称
最佳答案
您需要一个返回计算机名称的方法,或者如果名称是公共(public)的,则只需执行“list[k-1].name”即可。
关于java - 如何打印一行中的第二个单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23121321/