2026年程序员面试题目集及解析.docxVIP

  • 4
  • 0
  • 约9.54千字
  • 约 28页
  • 2026-01-05 发布于福建
  • 举报

第PAGE页共NUMPAGES页

2026年程序员面试题目集及解析

一、编程语言基础(5题,每题10分)

1.题目:

请编写一段Java代码,实现一个方法,输入一个字符串,返回该字符串中所有字符的出现次数。例如,输入hello,返回结果为:h:1,e:1,l:2,o:1。

答案:

java

importjava.util.HashMap;

importjava.util.Map;

publicclassCharacterCount{

publicstaticvoidmain(String[]args){

Stringinput=hello;

MapCharacter,IntegercountMap=countCharacters(input);

for(Map.EntryCharacter,Integerentry:countMap.entrySet()){

System.out.print(entry.getKey()+:+entry.getValue()+,);

}

}

publicstaticMapCharacter,IntegercountCharacters(Stringinput){

MapCharacter,IntegercountMap=newHashMap();

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档