美文网首页
Data Structures

Data Structures

作者: 我是阿喵酱 | 来源:发表于2018-02-04 16:36 被阅读0次

    Data Structures
    Learn to create, manipulate, and store information in data structures.

    Instance

    import java.util.*;
    
    public class Olympics {
    
        public static void main(String[] args) {
    
            //Some Olympic sports 
    
            ArrayList<String> olympicSports = new ArrayList<String>();
            olympicSports.add("Archery");
            olympicSports.add("Boxing");
            olympicSports.add("Cricket");
            olympicSports.add("Diving");
    
            System.out.println("There are " + olympicSports.size() + " Olympic sports in this list. They are: ");
    
            for (String sport: olympicSports) {
                System.out.println(sport);
            }
    
            //Host cities and the year they hosted the summer Olympics
    
            HashMap<String, Integer> hostCities = new HashMap<String, Integer>();
    
            hostCities.put("Beijing", 2008);
            hostCities.put("London", 2012);
            hostCities.put("Rio de Janeiro", 2016);
    
            for (String city: hostCities.keySet()) {
                
                if (hostCities.get(city) < 2016) {
    
                    System.out.println(city + " hosted the summer Olympics in " + hostCities.get(city) + ".");
    
                } else {
    
                    System.out.println(city + " will host the summer Olympics in " + hostCities.get(city) + ".");
    
                }
            }
    
        }
    
    }
    

    相关文章

      网友评论

          本文标题:Data Structures

          本文链接:https://www.haomeiwen.com/subject/yibbkxtx.html