不要用键盘手敲题给数据、字符串,免得空格数量不对:
import java.util.*; public class Main { public static void main(String[] args){ Scanner sc = new Scanner(System.in); String[] str = { "200-OK", "202-Accepted", "400-Bad Request", "403-Forbidden", "404-Not Found", "500-Internal Server Error", "502-Bad Gateway"}; Map<String, String> m = new HashMap<>(); for(String s : str){ String[] t = s.split("[-]"); m.put(t[0], t[1]); } while (sc.hasNext()){ System.out.println(m.get(sc.nextLine())); } } }