結果

問題 No.222 引き算と足し算
ユーザー kuramu
提出日時 2016-02-11 10:05:38
言語 Java
(openjdk 23)
結果
AC  
実行時間 57 ms / 1,000 ms
コード長 1,032 bytes
コンパイル時間 2,221 ms
コンパイル使用メモリ 77,224 KB
実行使用メモリ 37,156 KB
最終ジャッジ日時 2024-11-15 22:10:05
合計ジャッジ時間 5,066 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
	 public static void main(String[] args) {
	      BufferedReader stdReader =new BufferedReader(new InputStreamReader(System.in));
	      try {
	    	  String line = stdReader.readLine();
	    	  String op = "";
	    	  int a = 0;
	    	  int b = 0;
	    	  for(int i=1;i<line.length();i++){
	    		  if(line.charAt(i)=='+'){
	    			  op = "+";
	    			  a = Integer.parseInt(line.substring(0,i));
	    			  b = Integer.parseInt(line.substring(i+1,line.length()));
	    			  break;
	    		  }else if(line.charAt(i)=='-'){
	    			  op = "-";
	    			  a = Integer.parseInt(line.substring(0,i));
	    			  b = Integer.parseInt(line.substring(i+1,line.length()));
	    			  break;
	    		  }
	    	  }	    	  
	    	  if(op.equals("+")){
	    		  System.out.println(a-b);
	    	  }else if(op.equals("-")){
	    		  System.out.println(a+b);
	    	  }
	      } catch (IOException e) {
			e.printStackTrace();
	      }
	}
}
0