java中如何解决从用户输入的一组猫中辩别其中一只猫的问题

问题描述:

java中如何解决从用户输入的一组猫中辩别其中一只猫的问题,首先定义几只猫,它们的身高,体重,年龄不同,然后由用户输入的身高,体重,年龄找到对应的猫,这个怎么来



```java
package com.lingoace.edu.controller;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * @title: test
 * @date 2021/11/8上午11:09
 */
public class test {

    public static void main(String[] args) {

        Map<String, Map> map = new HashMap<>();

        Map<String, String> infoMap_yellow = new HashMap<>();
        infoMap_yellow.put("身高", "20");
        infoMap_yellow.put("体重", "10");
        infoMap_yellow.put("年龄", "20");

        Map<String, String> infoMap_white = new HashMap<>();
        infoMap_white.put("身高", "201");
        infoMap_white.put("体重", "101");
        infoMap_white.put("年龄", "201");

        map.put("小黄猫", infoMap_yellow);
        map.put("小白猫", infoMap_white);

        Scanner scanner = new Scanner(System.in);

        System.out.println("请输入想要查询的猫猫的身高");
        String height = scanner.nextLine();

        System.out.println("请输入想要查询的猫猫的体重");
        String weight = scanner.nextLine();

        System.out.println("请输入想要查询的猫猫的年龄");
        String age = scanner.nextLine();

        String infoKey = null;
        for (String key : map.keySet()) {
            Map info = map.get(key);
            if (info.get("身高").equals(height) && info.get("体重").equals(weight) && info.get("年龄").equals(age)) {
                infoKey = key;
                System.out.println("您想要查询的是:" + key + "信息:" + info.toString());
                break;
            }

        }
        if (infoKey == null) {
            System.out.println("查询不到");
        }


    }
}


```