使用计数器在数组中搜索用户输入字

时间:2015-04-29 19:04:51

标签: java arrays user-input

我要做的是创建一个具有set数组的程序,程序要求用户输入一个单词,程序找到单词并输出它被使用了多少次。因此,例如我设置的数组(每个字母都在它自己的数组编号中)是“热量理论”,因为它在文本中有几个“the”。我希望用户输入'the'并将输出设置为2(因为第一个是大写的)。或者,如果用户想要输入'e',他将得到3。

我有阵列设置,但我仍然在寻找一种设置程序的方法,这样如果用户输入多个字母,它一次可以查看多个字母。

我假设我需要为扫描仪输入.length,在其周围输入计数器,然后让阵列随之移动。我会更多地了解这一点,如果你们能帮助我,我会很感激。

修改

public class SearchableSentence {
public static void main(String[] args) throws IOException {

double count = 0;   

String[] stringer = {"T","h","e"," ","t","h","e","o","r","y"," ","o","f"," ","T","h","e","o"," ","i","s"," ","t","h","a","t"," ","t","h","e"," ","o","t","h","e","r"," ","t","h","i","n","g","s"," ","a","r","e"," ","a"," ","b","o","t","h","e","r","."};

0 个答案:

没有答案