我正在練習算法,並且我有這個問題,我必須指出單詞中每個字母出現的次數。例如輸入= 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您的意思是什麼 –