import java.io.*;
class Calc
{
public static void main(String args[])
{
boolean end_flg = true;
String newOPE = "";
String oldOPE = "";
int Ans = 0;
newOPE = "+";
oldOPE = newOPE;
System.out.println(String.format("現在は'%s'モードです。", oldOPE));
try
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String in_num = "";
double num = 0;
while(end_flg == true)
{
try
{
if(newOPE != oldOPE)
{
System.out.println(String.format("現在は'%s'モードです。", newOPE));
oldOPE = newOPE;
}
in_num = br.readLine();
switch(oldOPE)
{
case "+":
num += Integer.parseInt(in_num);
break;
case "-":
num -= Integer.parseInt(in_num);
break;
case "*":
num *= Integer.parseInt(in_num);
break;
case "/":
num /= Integer.parseInt(in_num);
break;
}
System.out.println(String.format("結果:%.0f",num));
}
catch(NumberFormatException e)
{
char ch = in_num.charAt(0);
switch(ch)
{
case '+':
newOPE = "+";
break;
case '-':
newOPE = "-";
break;
case '*':
newOPE = "*";
break;
case '/':
newOPE = "/";
break;
case 'q':
end_flg = false;
break;
default:
System.out.println(String.format("数値を入力してください。"));
break;
}
}
}
}
catch(IOException e)
{
System.out.println(String.format("エラーです。"));
}
}
}
Javaセミナー2014/福留早紀