0
0

【Java】ABC081A_ Placing Marbles #AtCoder

Posted at

自分用にAtCoderの解答をまとめていきます。誤った情報があったら、申し訳ございません。

覚えること

  • charAtメソッド
    文字列からn番目の文字列を引き出すためのStringクラスのメソッド。文字列の先頭は0文字目。

コード

ABC081A_PlacingMarbles
import java.util.Scanner;

public class ABC081A_PlacingMarbles {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            String str = sc.next();
            System.out.println(cal(str));
            }
        } 

    public static int cal (String str) {
        int count = 0;
        for (int i = 0 ; i < str.length() ;i++ ){
            if (str.charAt(i) == '1'){
                count++;
            }
        }
        return count;
    }
}

参考にしたサイト

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0