Created
October 24, 2012 09:10
-
-
Save KazumasaSUGAYA/3945002 to your computer and use it in GitHub Desktop.
Simple Calculator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
【問題】 | |
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("?")){ | |
} | |
} | |
} | |
throws IOExceptionの必要性を説明できるようにする。リソースの解放も。
Streamとは?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
1行入力してenterを押下すると、結果が出力されるようする。また、次の計算式を受け付けられるようになっているように修正する。