前提・実現したいこと
Javaの初心者です。
キーボードから入力した文字が何回出現したのか、
下記のような出現回数を数えるプログラムを作成したいです。
文字を入力:s
文字を入力:a
文字を入力:a
文字を入力:c
aの入力回数は:2
いくら調べてもやり方がわからないので、教えていただきたいです。
発生している問題・エラーメッセージ
シンボルを見つけられません x = word.count('a'); シンボル:メソッドcount(char) 場所:タイプStringの変数 ans
該当のソースコード
java
1Scanner sc = new Scanner(System.in); 2System.out.print("文字を入力:") 3String word1 = sc.nextInt(); 4System.out.print("文字を入力:") 5String word2 = sc.nextInt(); 6System.out.print("文字を入力:") 7String word3 = sc.nextInt(); 8System.out.print("文字を入力:") 9String word4 = sc.nextInt(); 10 11String word = word1 + word2 + word3+ word4; 12int x = 0; 13x = word.count('a') 14System.out.print("aの入力回数は:" + x);
試したこと
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。