我正在练习算法,并且我有这个问题,我必须指出单词中每个字母出现的次数。例如输入= floor,输出= f1l1o2r1。我有以下代码:Java - 单词中每个字母的打印量
public static void main(String[] args) {// TODO code application logic here
Scanner inword = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
System.out.println("Enter word");
String word = inword.nextLine();
int length = word.length();
char[] wordArray = word.toCharArray();
for(int i = 0; i<length; i++){
int count = StringUtils.countMatches(word, String.valueOf(wordArray[i]));
System.out.print(wordArray[i] + count);
}
}
,而是我得到这个作为输出:103109113113115
,当我进入楼层输入
将文章输出为文字,而不是图像 –
@ChrisMowforth您的意思是什么 –