package hanjagonghomework;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Calculater {
	private static BufferedReader in;
	static{
		in = new BufferedReader(new InputStreamReader(System.in));
	}
	public static void main(String[] args) throws IOException{
		int su1 = 0, su2 = 0, tot = 0;
		char yon = 0, flag = 0;
		while(true){
			do{
				flag = 0;
				try{
					System.out.print("SU1 = ");
					su1 = Integer.parseInt(in.readLine());
				}catch(NumberFormatException nfe){
					System.out.println("숫자만 입력 가능!");
					flag = 1;
				}
			}while(flag != 0);
			
			do{
				
				do{
					flag = 0;
					String str = "";
					try{
						System.out.println("YON(+, -, *, /) = ");
						str = in.readLine();
						yon = str.charAt(0);
					}catch(StringIndexOutOfBoundsException siooe){
						System.out.println("뭐든 입력해야 합니다.");
						flag = 1;
					}
					if(str.length() != 1){
						System.out.println("연산자는 1자리여야 합니다.");
						flag = 1;
					}
				}while(flag != 0 || yon != '+' && yon != '-' && yon!= '*' && yon != '/');
				do{
					flag = 0;
					try{
						System.out.print("SU2 = ");
						su2 = Integer.parseInt(in.readLine());
					}catch(NumberFormatException nfe){
						System.out.println("숫자만 입력 가능!");
						flag = 1;
					}
				}while(flag != 0);
				flag = 0;
				try{
					switch(yon){
					case '+' : tot = su1 + su2; break;
					case '-' : tot = su1 - su2; break;
					case '*' : tot = su1 * su2; break;
					case '/' : tot = su1 / su2; break;
					}
				}catch(ArithmeticException ae){
					System.out.println("0으로 나눌 수는 없습니다.");
					flag = 1;
				}
				
			}while(flag != 0);
			System.out.println(su1 + "" + yon + "" + su2 + "=" + tot);
		}
	}
}
- 자바가 문자를 받아서 그걸로 Switch 돌리는건 생각도 못했는데 되니까 신기하네요
 
- 예시에 나와 있는걸 어떻게 고칠까 하다가 생각나는게 없어서 생각하는걸 그만둔다.