結果
問題 |
No.289 数字を全て足そう
|
ユーザー |
|
提出日時 | 2023-06-05 12:47:45 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 595 bytes |
コンパイル時間 | 2,339 ms |
コンパイル使用メモリ | 74,640 KB |
実行使用メモリ | 57,668 KB |
最終ジャッジ日時 | 2024-12-29 06:02:09 |
合計ジャッジ時間 | 6,806 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 3 WA * 18 |
ソースコード
import java.util.Scanner; import java.lang.Integer; public class Main { public static void main(String[] args) { try{ Scanner sc = new Scanner(System.in); String s = sc.next(); String intStr = s.replaceAll("[^0-9]",""); int number = Integer.parseInt(intStr); System.out.println(sumDigits(number)); }catch(NumberFormatException e){ System.out.println(0); } } public static int sumDigits(int n) { int sum = 0; while (n != 0) { sum += n % 10; n /= 10; } return sum; } }