计算方法中的出现次数 [英] counting occurances in a method

查看:86
本文介绍了计算方法中的出现次数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

im创建了一种方法来计算另一种方法中随机字符的出现,但是我似乎无法弄清楚如何从另一种方法中引入随机字符,代码应该创建一个由26个整数组成的数组,然后进行计数和存储随机字符的出现,这是我到目前为止的代码:

im creating a method that counts the occurances of random characters in another method but i cant seem to figure out how to bring in the random characters in from the other method the code is supposed to create an array of 26 integers then count and store the occurances of the random characters this is my code up until now:

      // generates random characters
public void add (char fromChar, char toChar){      
int range = toChar - fromChar;
int seed = fromChar * toChar;
Random rr = new Random(seed);
for (int i = 0; i < charArray; ++i) {
    char randomChar = (char)(fromChar + rr.nextInt(range));
    System.out.println("Next character: " + randomChar);
}   
 
public int[] countLetters(){ //method im working on
        int [] countLetters =new int[26];
       char current;
       
for(int i=0; i<countletters.length;>   current=.charAt(i);
    if (current >= 'a' && current <= 'z'){
       countLetters[current-'a']++;
   }
}
        return null;   
    }

推荐答案

您可以创建要搜索成员变量的数组,或者最好将其作为参数传递.
You make the array you want to search a member variable or, better yet, pass it in as a parameter.


这篇关于计算方法中的出现次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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