-
book
- <pre class="cpp" name="code"><img src="http://img.blog.csdn.net/20171130174554451" alt="">package Kuang;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.Scanner;
- public class Test {
- public static void main(String[] args) {
-
- List<Book> bookList = new ArrayList<Book>();
- bookList.add(new Book("英语", 29.99));
- bookList.add(new Book("数学", 50));
- bookList.add(new Book("化学", 30));
- bookList.add(new Book("生物", 30));
- bookList.add(new Book("历史", 30));
- System.out.println("请输入价格:
");
- Book book = new Book("对比价格", 50);
- System.out.println(book.name + book.price);
- for (int i = 0; i < bookList.size(); i++
-
- {
- if (book.compareTo(bookList.get(i)
- System.out.println((bookList.get(i)
-
-
- }System.out.println("价格相同的:"+(book.price));
-
-
-
-
-
-
-
-
-
- }
-
- }</pre><br>
- package Kuang;public class Book implements Comparable<Book>{String name;Double price;public Book (String nm,double p){name=nm;price=p;}@Overridepublic int compareTo(Book o) {
- <pre></pre>
- <br>
-
-
相关阅读:
十四、自定义构建购物计算组件&表单组件
从微信小程序到鸿蒙js开发【04】——list组件
HarmonyOS应用开发-Component体系介绍(一)
HarmonyOS单模块编译与源码导读
烧录失败导致boot无法加载的解决措施,再也不怕烧成砖了
从微信小程序到鸿蒙js开发【03】——fetch获取数据&简单天气预报
抛弃床的温暖,只为了它丨云库一款跑在鸿蒙系统上的应用丨篇二
swift 弹窗
Swift字符串常用操作总结
swift 随机数
-
原文地址:https://www.cnblogs.com/spsglz/p/8017890.html
Copyright © 2020-2023
润新知