计算器

下午作业做的一个小程序:

package work09_20;

import java.io.IOException;
import java.util.Scanner;

/*11*/
public class Test08 {
	public static void main(String[] args) throws IOException {
		js:
		while(true){
			Scanner scan = new Scanner(System.in);
			System.out.println("请选择操作     1-计算      2-退出:");
			String s = scan.next();
			int x = Integer.parseInt(s);
			switch (x) {
			case 1:
				scan = new Scanner(System.in);
				System.out.println("输入操作数1:");
				String s1 = scan.next();
				double m1 = Double.parseDouble(s1);

				System.out.println("输入运算符 + - * /:");
				String s2 = scan.next();
				char m2 = s2.charAt(0);

				System.out.println("输入操作数2:");
				String s3 = scan.next();
				double m3 = Double.parseDouble(s3);
				
				System.out.println("计算结果为:");
				System.out.print(m1 + "" + m2 + "" + m3 + "=");
				if (m2 == '+') {
					System.out.println(m1 + m3);
					continue js;
				} else if (m2 == '-') {
					System.out.println(m1 - m3);
					continue js;
				} else if (m2 == '*') {
					System.out.println(m1 * m3);
					continue js;
				} else if (m2 == '/') {
					System.out.println(m1 / m3);
					continue js;
				}
			case 2:
				System.exit(1);
			}
		}
	}
}
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值