zoukankan      html  css  js  c++  java
  • 考试第七题

    package test7;
    
    public class Penguin {
    
        
    private String name;
    private String gender;
    
    public String getName() {
        return name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    public String getGender() {
        return gender;
    }
    
    public void setGender(String gender) {
        this.gender = gender;
    }
    
    public Penguin(String name, String gender) {
        super();
        this.name = name;
        this.gender = gender;
    }
     
     
     
        
        
    }
    package test7;
    
    import java.util.HashMap;
    import java.util.Map;
    import java.util.Scanner;
    
    public class Test2 {
    
        static Scanner sc = new Scanner(System.in);
    
        public static void main(String[] args) {
    
            Map<String, String> map = new HashMap<String, String>();
    
            map.put("欧欧", "Q仔");
            map.put("亚亚", "Q妹");
            map.put("菲菲", "Q妹");
            map.put("美美", "Q妹");
    
            System.out.println("共有" + map.size() + "只企鹅。");
            System.out.println("分别是:");
            for (Map.Entry<String, String> penguin : map.entrySet()) {
    
                System.out.println(penguin.getKey() + " " + penguin.getValue());
    
            }
            System.out.println("请输入您要删除的企鹅的姓名:");
            String choose = sc.next();
    //        for (Map.Entry<String, String> penguin: map.entrySet()) {
    //            
    //            if(!penguin.getKey().equals(choose)) {
    //                
    //                System.out.println("找不到您要删除的企鹅,请重新输入:");
    //                sc.next();
    //            }else {
    //                
    //            }
    //        }
    
            while (!map.containsKey(choose)) {
    
                System.out.println("找不到您要删除的企鹅,请重新输入:");
                choose = sc.next();
    //                return;
            }
    
            map.remove(choose);
    
            System.out.println("删除成功!");
            System.out.println("删除后还有:" + map.size() + "只企鹅");
            System.out.println("分别是:");
            for (Map.Entry<String, String> penguin : map.entrySet()) {
    
                System.out.println(penguin.getKey() + " " + penguin.getValue());
    
            }
        }
    
    }

  • 相关阅读:
    springboot 配置
    spring boot配置分页插件
    mongodb 操作
    java基础知识
    java设计模式
    /cat/cpuinfo信息查看
    app接口开发
    基于OpenAM系列的SSO----基础
    关于Linux下的连接文件学习总结
    YII :将oracle中timestamp 字段正常显示在页面中
  • 原文地址:https://www.cnblogs.com/bichen-01/p/11336503.html
Copyright © 2011-2022 走看看