In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to use the TreeSet collection, the content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.
Requirements: keyboard input 5 student information (name, Chinese score, math score, English score), according to the total score from high to low output to the console. Analysis: 1. Create keyboard input object
2. Create the TreeSet collection, implement the Comparator interface using anonymous inner classes, and override the compara method.
3. Judge the number of elements in the set and add elements to it
4. Traverse the collection
Class Demo_TreeSet {
Public static void main (String [] args) {
Scanner sc = new Scanner (System.in)
System.out.println ("Please enter the student's score format, Chinese, math, English, total score")
TreeSet ts = new TreeSet (new Comparator {
Public int compara (Student S1, Student s2)
Int num = s2.getSum ()-s1.getSum ()
Return num = = 0? 1: num
});
While (ts.size ()
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.