import
1 2 3public class Main { 4 public static void main(String[] args) { 5 Scanner a = new Scanner(System.in); 6 int N = a.nextInt(); 7 int sc = 0; 8 int bc = 0; 9 for (int n = 0; n < N; n++){ 10 String s_n = a.nextLine(); 11 if (s_n.equals("strike")){ 12 System.out.println("strike!"); 13 sc += 1; 14 } 15 else { 16 System.out.println("ball!"); 17 bc += 1;} 18 } 19 if (sc == 3) System.out.println("out!"); 20 if (bc == 4) System.out.println("fourball!"); 21 } 22 }
N回数分入力された文字列の判定を行たいのですが1回目の判定が2回出力されてしまいます。
具体的には以下の通りです。
出力したい文字
ball!
strike!
ball!
strike!
出力される文字
ball!
ball!
strike!
ball!
strike!
なぜこうなってしまうのかわかりません。
どなたかご教授ください。
回答4件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/09/28 08:07