結果

問題 No.289 数字を全て足そう
ユーザー tsunabittsunabit
提出日時 2018-04-08 18:47:35
言語 Java21
(openjdk 21)
結果
AC  
実行時間 140 ms / 1,000 ms
コード長 1,268 bytes
コンパイル時間 4,018 ms
コンパイル使用メモリ 73,980 KB
実行使用メモリ 56,068 KB
最終ジャッジ日時 2023-09-09 03:12:32
合計ジャッジ時間 8,192 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
55,872 KB
testcase_01 AC 119 ms
55,348 KB
testcase_02 AC 120 ms
55,652 KB
testcase_03 AC 119 ms
55,960 KB
testcase_04 AC 120 ms
55,800 KB
testcase_05 AC 130 ms
55,456 KB
testcase_06 AC 127 ms
55,764 KB
testcase_07 AC 140 ms
55,648 KB
testcase_08 AC 140 ms
55,744 KB
testcase_09 AC 131 ms
55,896 KB
testcase_10 AC 137 ms
55,640 KB
testcase_11 AC 137 ms
55,772 KB
testcase_12 AC 139 ms
55,868 KB
testcase_13 AC 136 ms
55,764 KB
testcase_14 AC 140 ms
55,740 KB
testcase_15 AC 137 ms
55,996 KB
testcase_16 AC 136 ms
55,964 KB
testcase_17 AC 138 ms
56,068 KB
testcase_18 AC 139 ms
55,860 KB
testcase_19 AC 138 ms
56,032 KB
testcase_20 AC 136 ms
55,840 KB
testcase_21 AC 119 ms
55,968 KB
testcase_22 AC 139 ms
55,644 KB
testcase_23 AC 139 ms
55,876 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

// 問題文
// 文字列Sが与えられるので, その中のそれぞれの数字を1桁の数値とみなして, 全ての合計値を求めてください.
// 例えば1test23という文字列の数字の合計値は1+2+3=6
// となる.
// 2016/05/31 追記
// 注意: 数字がない場合は0を出力してください。
// ***
// 入力
// 1≤|S|≤10000
// |S| は文字列Sの長さである.
// 文字列Sは半角英数字のみで構成される.
// ***
// 出力
// 各数字の合計値を出力してください。

public class No289 {
    public static void main(String[] args) {
        // 標準入力から読み込む際に、Scannerオブジェクトを使う。
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        // System.out.println(str);
        char[] c = str.toCharArray();
        int out = 0;
        for(int i = 0; i < str.length(); i++) {
            // System.out.println(c[i]);
            if(Character.getNumericValue(c[i]) > 0 && Character.getNumericValue(c[i]) < 10) {
                // System.out.println(Character.getNumericValue(c[i]));
                out += Character.getNumericValue(c[i]);
            }
        }
        System.out.println(out);
    }
}
0