输入两个数及符号,完成简单加减乘除计算(简单计算器)

package demo10_28;
import java.util.Scanner;

public class homework01 {

	public static void main(String[] args) {
		System.out.println("请输入两个数和符号");//输入时提示
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		String str = sc.next();//输入语句
		switch (str) {//判断str,以str的结果来决定接下来的步骤
		case "+"://执行过程
			System.out.println(x + y);
			break;
		case "-":
			System.out.println(x - y);
			break;
		case "*":
			System.out.println(x * y);
			break;
		case "/":
			System.out.println(x / y);
			break;
		default:
			System.out.println("输入错误");
		}
	}
}

上一篇:360数科第三季度财报:输出积木式技术样板,科技业务占比提升至28%


下一篇:三、Java入门