ABC101
ABC101B
考え方
与えられた数字の列に対して一文字ずつ取り出し、加えて行く。
コード
int count; for( int i = 0; i < 長さ ; i ++ ) { int a = Integer.ParseInt( String.substring( i ,i + 1); count += a; }
使用メソッド
返り値( int型 )Integer.Parseint( String s );
文字列 s を10進数の int型 で返す。
返り値( String型 )str.substring( int a , int b );
文字列 str の a 番目から b 番目までの文字を返す。(0スタート)
コメント
文字列を int型 に変換できるのは便利
substring は文字列から特定の文字を取り出す時に使えそう