結果

問題 No.289 数字を全て足そう
ユーザー kenji_shioya
提出日時 2016-05-24 04:53:20
言語 Java
(openjdk 23)
結果
AC  
実行時間 225 ms / 1,000 ms
コード長 632 bytes
コンパイル時間 4,332 ms
コンパイル使用メモリ 75,056 KB
実行使用メモリ 57,528 KB
最終ジャッジ日時 2024-10-08 01:00:31
合計ジャッジ時間 9,910 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

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