zoukankan      html  css  js  c++  java
  • 十五周作业

    1.需求说明:使用HashMap存储多个企鹅信息,然后统一使用Iterator进行遍历。

    package lhy;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.Map;
    import java.util.Set;
    public class demo {
        public static void main(String[] args) {
                // TODO Auto-generated method stub
                Map<String,String> map=new HashMap();
                map.put("欧欧","Q仔");
                map.put("亚亚","Q妹");
                map.put("美美","Q妹");
                map.put("菲菲","Q妹");
                System.out.println("使用Iterator遍历,企鹅的昵称和品种分别是:");
                Set<String> keyset = map.keySet();
                Iterator<String> iter = keyset.iterator();
                while(iter.hasNext()){
                    String key=iter.next();
                    String value=map.get(key);
                    System.out.println(key+"	"+value);
                }
                System.out.println("使用foreach遍历,所有企鹅的昵称和品种分别是:");
                for (String key : keyset) {
                    String sex = map.get(key);
                    System.out.println(key + "	" + sex);
                }
            }
        }

    2.需求说明:在上机3的基础上,为企鹅添加一个编号,并作为键存储多个企鹅信息到应用泛型的HashMap集合。使用Iterator、foreach语句进行遍历。

    package lhy;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.Map;
    import java.util.Set;
    public class demo {
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            Map<String,String> map=new HashMap();
            map.put("欧欧","Q仔");
            map.put("亚亚","Q妹");
            map.put("美美","Q妹");
            map.put("菲菲","Q妹");
            System.out.println("使用Iterator遍历,企鹅的昵称和品种分别是:");
            Set<String> keyset = map.keySet();
            Iterator<String> iter = keyset.iterator();
            while(iter.hasNext()){
                String key=iter.next();
                String value=map.get(key);
                System.out.println(key+"	"+value);
            }
            System.out.println("使用foreach遍历,所有企鹅的昵称和品种分别是:");
            for (String key : keyset) {
                String sex = map.get(key);
                System.out.println(key + "	" + sex);
            }
        }
    }
  • 相关阅读:
    Shared Memory in Windows NT
    Layered Memory Management in Win32
    软件项目管理的75条建议
    Load pdbs when you need it
    Stray pointer 野指针
    About the Rebase and Bind operation in the production of software
    About "Serious Error: No RTTI Data"
    Realizing 4 GB of Address Space[MSDN]
    [bbk4397] 第1集 第一章 AMS介绍
    [bbk3204] 第67集 Chapter 17Monitoring and Detecting Lock Contention(00)
  • 原文地址:https://www.cnblogs.com/527x/p/13150552.html
Copyright © 2011-2022 走看看