Calculator

import java.util.Scanner;
public class Sum_
{
	public static void main(String args[])
	{
		int x,y;
		char k;
		String str ;
		Scanner reader= new Scanner(System.in);
		while((str=reader.nextLine())!=null)
		{
			k=str.charAt(1);
			x=Integer.parseInt(String.valueOf(str.charAt(0)));
			y=Integer.parseInt(String.valueOf(str.charAt(2)));
			switch(k)
			{
				case '+':
							System.out.printf("%d
",x+y);
							break;
				case '-':
							System.out.printf("%d
",x-y);
							break;
				case '*':
							System.out.printf("%d
",x*y);
							break;
				case '/':
							System.out.printf("%d
",(double)x/(double)y);
							break;
				default :
							System.out.printf("输入错误
");
							break;
			}
			str="";
			//System.out.printf("%d",);
		}
	}
}

原文地址:https://www.cnblogs.com/WALLACE-S-BOOK/p/9732363.html