Skip to content

Instantly share code, notes, and snippets.

@KazumasaSUGAYA
Created October 24, 2012 09:10
Show Gist options
  • Save KazumasaSUGAYA/3945002 to your computer and use it in GitHub Desktop.
Save KazumasaSUGAYA/3945002 to your computer and use it in GitHub Desktop.
Simple Calculator
【問題】
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=10010
【Scannerクラス】
http://docs.oracle.com/javase/jp/6/api/java/util/Scanner.html
package example.excercise;
import java.io.IOException;
import java.util.Scanner;
public class SimpleCalculator {
public static void main(String[] args) throws IOException {
Scanner input = new Scanner(System.in);
int a = input.nextInt();
String op = input.next();
int b = input.nextInt();
if (op.equals("+")) {
System.out.println(a + b);
} else if (op.equals("-")) {
System.out.println(a - b);
} else if (op.equals("*")) {
System.out.println(a * b);
} else if (op.equals("/")) {
System.out.println(a / b);
}else if(op.equals("?")){
}
}
}
@KazumasaSUGAYA
Copy link
Author

1行入力してenterを押下すると、結果が出力されるようする。また、次の計算式を受け付けられるようになっているように修正する。

@KazumasaSUGAYA
Copy link
Author

throws IOExceptionの必要性を説明できるようにする。リソースの解放も。

@KazumasaSUGAYA
Copy link
Author

Streamとは?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment