結果

問題 No.289 数字を全て足そう
ユーザー Yosuke Yamaguchi
提出日時 2020-12-27 23:16:40
言語 Java
(openjdk 23)
結果
AC  
実行時間 236 ms / 1,000 ms
コード長 1,030 bytes
コンパイル時間 2,754 ms
コンパイル使用メモリ 82,348 KB
実行使用メモリ 47,340 KB
最終ジャッジ日時 2024-10-01 22:11:56
合計ジャッジ時間 8,251 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

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

        // String 1つ分を読み込む
        String s = sc.next();
        
        // String s = "1test23";
        
        List<String> inputList = Arrays.asList(s.split(""));
        List<Integer> numbers = inputList.stream().filter(n -> isNumber(n)).map(n -> Integer.parseInt(n)).collect(Collectors.toList());

        int result = 0;
        for (Integer n : numbers) {
            result += n;
        }
        // 標準出力に書き出す。
        System.out.println(result);
    }
    
    public static boolean isNumber(String num) {
        try {
            Integer.parseInt(num);
            return true;
            } catch (NumberFormatException e) {
            return false;
        }
    }
}
0