Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 统计每个字符_Java_Arrays - Fatal编程技术网

Java 统计每个字符

Java 统计每个字符,java,arrays,Java,Arrays,注意:对于计数器数组,每个UTF-16字符一个计数器,统计每个字符的使用情况。 对于我正在编写的一个程序,我试图统计一个特定单词中的每个字符。到目前为止, public void tally(String word) { if ((word == null) || (word.length() == 0)) return; (Insert here) } 因为我有“Insert here”的地方就是我试图统计一个特定单词中的每个字符

注意:对于计数器数组,每个UTF-16字符一个计数器,统计每个字符的使用情况。
对于我正在编写的一个程序,我试图统计一个特定单词中的每个字符。到目前为止,

   public void tally(String word)   
   {  
      if ((word == null) || (word.length() == 0))
      return;

   (Insert here)

   }
因为我有“Insert here”的地方就是我试图统计一个特定单词中的每个字符。有人知道简单的方法吗?

  • 创建地图
  • 从每个字符的第一个字符开始,检查字符键是否存在于映射中,如果存在,则将键的值增加一
  • 如果不存在,请将字符作为键插入,将值作为一个。完成后,打印地图

    • 这看起来像是家庭作业,所以我将给出一些简短的提示

      • 可以使用以下命令将字符串拆分为字符:
      • 您可以使用
      • 您可以将值存储在
      公共空白计数(字符串字)
      {  
      整数计数;
      if(word==null)
      {
      返回计数;
      }
      其他的
      {
      char[]ca;
      ca=单词toCharArray();
      对于(int i=0;i

      这将显示单词中总共有多少个字母。我想,从这里,你可以完成剩下的部分。

      请你给我举个例子好吗?我想看看你是否能找到某种
      MultiSet
      库我能在我的Tall方法中构建它吗?还是创建一个新方法更明智?我认为它非常适合该方法。
      public void tally(String word)   
      {  
            int count;
            if (word == null)
            {
                 return count;
            }
            else
            {
                 char[] ca;
                 ca = word.toCharArray();
                 for(int i = 0; i < ca.length; i++)
                 {
                       count++;
                 }
                 return count;
            }