結果

問題 No.289 数字を全て足そう
ユーザー kenji_shioyakenji_shioya
提出日時 2016-05-24 04:53:20
言語 Java21
(openjdk 21)
結果
AC  
実行時間 187 ms / 1,000 ms
コード長 632 bytes
コンパイル時間 3,859 ms
コンパイル使用メモリ 74,792 KB
実行使用メモリ 46,700 KB
最終ジャッジ日時 2024-04-16 21:08:50
合計ジャッジ時間 8,175 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
41,796 KB
testcase_01 AC 108 ms
41,232 KB
testcase_02 AC 103 ms
41,276 KB
testcase_03 AC 118 ms
41,316 KB
testcase_04 AC 115 ms
41,780 KB
testcase_05 AC 139 ms
43,596 KB
testcase_06 AC 164 ms
43,076 KB
testcase_07 AC 187 ms
46,464 KB
testcase_08 AC 186 ms
46,136 KB
testcase_09 AC 158 ms
43,300 KB
testcase_10 AC 165 ms
44,576 KB
testcase_11 AC 167 ms
46,096 KB
testcase_12 AC 186 ms
46,644 KB
testcase_13 AC 168 ms
45,668 KB
testcase_14 AC 177 ms
46,700 KB
testcase_15 AC 167 ms
45,944 KB
testcase_16 AC 160 ms
45,864 KB
testcase_17 AC 177 ms
46,060 KB
testcase_18 AC 177 ms
46,592 KB
testcase_19 AC 162 ms
45,724 KB
testcase_20 AC 163 ms
46,276 KB
testcase_21 AC 113 ms
40,068 KB
testcase_22 AC 175 ms
46,512 KB
testcase_23 AC 149 ms
42,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Exercises7{
  public static void main (String[] args){

    Scanner sc = new Scanner(System.in);

    int sum = 0;
    String str = sc.next();
    String[] strs = str.split("", 0);

    for(int n = 0; n < strs.length; n++){
      // boolean flag = isNumber(strs[n]);
      if (isNumber(strs[n])){
        int num = Integer.parseInt(strs[n]);
        sum += num;
      }
    }

     System.out.println(sum);
  }

  public static boolean isNumber(String num){
    try{
      int n = Integer.parseInt(num);
      return true;
    }catch (NumberFormatException e){
      return false;
    }
  }
}
0