如何编写一种方法来计算每个字母A-Z或a-z在字符串中出现的频率 [英] how to write a method that computes how often each letter A-Z or a-z occurs in a string

查看:55
本文介绍了如何编写一种方法来计算每个字母A-Z或a-z在字符串中出现的频率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一种方法来计算每个字母A-Z或a-z在字符串中出现的频率.不要区分大小写字母.返回长度为26的数组.ith元素包含字母"a" + i或"A" + i在字符串中出现的次数.该字符串可能包含您应该跳过的其他字符.

我有以下代码:

I am trying to write a method that computes how often each letter A-Z or a-z occurs in a string. Don''t distinguish between upper- and lowercase letters. Return an array of length 26. The ith element contains the number of times that the letter ''a'' + i or ''A'' + i occurs in the string. The string may contain other characters that you should simply skip.

I have the following code:

public class Letters
{
   /**
      Counts the frequencies of letters A-Za-z in a string
      @param str a string
      @return an array of 26 counts. The i-th count is the number of occurrences
      of ''A'' + i or ''a'' + i.
   */
   public int[] letterFrequencies(String str)
   {
      ........

   }
}

推荐答案

我们不做作业:它的设置是有原因的.在这里,您可以考虑自己被告知的内容,并尝试理解它.也可以在那里帮助您的导师识别您的弱点,并将更多的注意力放在补救措施上.

自己尝试,您可能会发现它并不像您想的那么困难!
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!


有趣.来吧,认真,这是经典的家庭作业.

我可以告诉您,您应该使用此类: java.lang.String-javadoc [^ ]

这可能也有帮助- StringTokenizer [ ^ ]

读.想一想.那是开发软件的90%.编码只是将您的恶念转化为机器.
funny. come on, serious, this is a classic home work.

I can tell you that you should use this class: java.lang.String - javadoc[^]

This might also be helpfull - StringTokenizer[^]

Read. Think about it. That''s 90% of developing software. The coding is just the translation of your wicked thoughts into the machine.


这篇关于如何编写一种方法来计算每个字母A-Z或a-z在字符串中出现的频率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆