結果

問題 No.289 数字を全て足そう
ユーザー 水野嶺水野嶺
提出日時 2020-05-25 11:06:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 182 ms / 1,000 ms
コード長 688 bytes
コンパイル時間 2,089 ms
コンパイル使用メモリ 74,468 KB
実行使用メモリ 43,560 KB
最終ジャッジ日時 2024-04-21 03:41:39
合計ジャッジ時間 6,798 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
41,040 KB
testcase_01 AC 125 ms
40,968 KB
testcase_02 AC 115 ms
39,992 KB
testcase_03 AC 129 ms
40,944 KB
testcase_04 AC 124 ms
40,996 KB
testcase_05 AC 155 ms
42,392 KB
testcase_06 AC 146 ms
41,484 KB
testcase_07 AC 163 ms
42,768 KB
testcase_08 AC 165 ms
42,188 KB
testcase_09 AC 157 ms
42,020 KB
testcase_10 AC 161 ms
42,208 KB
testcase_11 AC 169 ms
42,744 KB
testcase_12 AC 172 ms
42,076 KB
testcase_13 AC 171 ms
42,440 KB
testcase_14 AC 182 ms
42,324 KB
testcase_15 AC 169 ms
42,128 KB
testcase_16 AC 160 ms
42,924 KB
testcase_17 AC 154 ms
42,568 KB
testcase_18 AC 176 ms
42,292 KB
testcase_19 AC 158 ms
42,868 KB
testcase_20 AC 163 ms
43,560 KB
testcase_21 AC 127 ms
40,836 KB
testcase_22 AC 168 ms
42,144 KB
testcase_23 AC 177 ms
42,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.lang.*;
import java.io.*;

class Main
{
	public static void main (String[] args) 
	{
		// 入力値の読み込み
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int goukei = 0;
		
		// 数字以外を除去
		String intStr = s.replaceAll("[^0-9]", "");
		
		if(!(intStr.equals(""))){
		
		// 分割してアレイリストに格納
		String[] split = intStr.split("");
		
		//配列の要素をひとつづつfor文でまわす
		for (String str : split) {
			
			// 文字列から数字に変換
			int num = Integer.parseInt(str);
			
			//配列の要素を足していく
			goukei += num;
		}
		}
		System.out.println(goukei);
	}
}
0