結果

問題 No.289 数字を全て足そう
ユーザー show258show258
提出日時 2017-04-04 02:52:01
言語 Java21
(openjdk 21)
結果
AC  
実行時間 137 ms / 1,000 ms
コード長 688 bytes
コンパイル時間 3,669 ms
コンパイル使用メモリ 72,816 KB
実行使用メモリ 56,912 KB
最終ジャッジ日時 2023-09-22 14:11:10
合計ジャッジ時間 8,670 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
55,736 KB
testcase_01 AC 113 ms
55,536 KB
testcase_02 AC 115 ms
55,840 KB
testcase_03 AC 114 ms
55,392 KB
testcase_04 AC 114 ms
55,864 KB
testcase_05 AC 125 ms
55,628 KB
testcase_06 AC 120 ms
56,008 KB
testcase_07 AC 133 ms
56,912 KB
testcase_08 AC 132 ms
55,964 KB
testcase_09 AC 123 ms
55,832 KB
testcase_10 AC 130 ms
55,960 KB
testcase_11 AC 135 ms
55,768 KB
testcase_12 AC 136 ms
55,452 KB
testcase_13 AC 131 ms
55,932 KB
testcase_14 AC 134 ms
55,748 KB
testcase_15 AC 131 ms
55,756 KB
testcase_16 AC 129 ms
55,760 KB
testcase_17 AC 130 ms
56,064 KB
testcase_18 AC 133 ms
55,772 KB
testcase_19 AC 130 ms
55,840 KB
testcase_20 AC 134 ms
55,680 KB
testcase_21 AC 115 ms
55,540 KB
testcase_22 AC 134 ms
55,728 KB
testcase_23 AC 137 ms
55,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class No289 {
  public static void main(String[] args) {
    // 標準入力から読み込む際に、Scannerオブジェクトを使う。
    Scanner sc = new Scanner(System.in);

    // String 入力文字列を読み込む
    String str = sc.next();

    sc.close(); // 標準入力をクローズ

    int sum = 0; //合計値変数を0にセット

    for (int i = 0; i < str.length(); i++) {
    //char ch = str.charAt(i);  //入力文字列のi番目をchに取得

      if(Character.isDigit(str.charAt(i))) {  //chが数字の場合
        sum += Character.getNumericValue(str.charAt(i));
      }
    }

    System.out.println(sum);

  }
}
0