結果

問題 No.289 数字を全て足そう
ユーザー TwinkleStar74TwinkleStar74
提出日時 2017-09-12 18:03:10
言語 Java21
(openjdk 21)
結果
AC  
実行時間 180 ms / 1,000 ms
コード長 1,013 bytes
コンパイル時間 2,245 ms
コンパイル使用メモリ 74,900 KB
実行使用メモリ 42,196 KB
最終ジャッジ日時 2024-04-25 07:07:37
合計ジャッジ時間 6,825 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
40,144 KB
testcase_01 AC 123 ms
41,216 KB
testcase_02 AC 109 ms
39,940 KB
testcase_03 AC 121 ms
40,960 KB
testcase_04 AC 111 ms
39,988 KB
testcase_05 AC 153 ms
41,496 KB
testcase_06 AC 148 ms
41,236 KB
testcase_07 AC 171 ms
41,732 KB
testcase_08 AC 156 ms
41,680 KB
testcase_09 AC 139 ms
41,516 KB
testcase_10 AC 156 ms
41,368 KB
testcase_11 AC 159 ms
41,764 KB
testcase_12 AC 174 ms
42,196 KB
testcase_13 AC 159 ms
41,664 KB
testcase_14 AC 180 ms
41,936 KB
testcase_15 AC 164 ms
41,756 KB
testcase_16 AC 149 ms
41,600 KB
testcase_17 AC 164 ms
41,900 KB
testcase_18 AC 173 ms
41,952 KB
testcase_19 AC 160 ms
41,252 KB
testcase_20 AC 163 ms
41,952 KB
testcase_21 AC 121 ms
40,968 KB
testcase_22 AC 167 ms
41,748 KB
testcase_23 AC 180 ms
41,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
 
class No289{
          public static void main(String[] args){

                     int sum =0;

                     Scanner sc = new Scanner(System.in);
                     String str1 = sc.nextLine();
                     String[] str2 = str1.split("");   //入力した文字を1文字ずつ配列に格納
                     String x = "123456789";   //一致するかの確認のため用意
 
                     for (int i=0; i<str2.length; i++){    //入力した文字を1つずつ検証
                               if (x.indexOf(str2[i])!=-1){   //文字列の数字と一致するなら
                                          int num = Integer.parseInt(str2[i]);   //文字を数値に変換
                                          sum += num; //数値を加算していく
                               }                                    
                     }

                     System.out.println(sum);
                     sc.close();
           }
}
0