其他分享
首页 > 其他分享> > 输入两个数及符号,完成简单加减乘除计算(简单计算器)

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

作者:互联网

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("输入错误");
		}
	}
}

标签:case,sc,System,break,println,简单,数及,out,加减乘除
来源: https://blog.csdn.net/weixin_43795407/article/details/123034917