数字を入力させ、その次にその数だけA,Bからなる文字列を入力させる。そのときaの数を返すプログラムについて。
プログラム
lang
1import java.io.BufferedReader; 2import java.io.IOException; 3import java.io.InputStreamReader; 4 5public class Sample16{ 6 7 public static void main(String[] args) throws IOException{ 8 System.out.println("入力"); 9 BufferedReader br = 10 new BufferedReader(new InputStreamReader(System.in)); 11 String str1 = br.readLine(); 12 String str2 = br.readLine(); 13 int num2 = number(str2); 14 int num1 = Integer.parseInt(str1); 15 16 System.out.println(num2); 17 } 18public static int number(String moji){ 19 int count=0; 20 for(int i=0;i<moji.length();i++){ 21 char kazu = moji.charAt(i); 22 if("A".equals(kazu)){ 23 count= count +1; 24 } 25 } 26 return count;
問題点
実行すると、num2が常に0になってしまいます。
間違いをお教えください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2017/08/12 13:08
2017/08/12 14:09
退会済みユーザー
2017/08/12 15:17