标签:scanner main blog code bre scan break system.in 数值
import java.util.Scanner; /** * @author 蓝色以太 * 通过键盘接收数值和字符,实现计算器功能。 */ public class Calculator { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.println("请输入第一个数值:"); double num1=sc.nextDouble(); System.out.println("请输入运算字符(+-*/):"); String ch=sc.next(); System.out.println("请输入第二个数值:"); double num2=sc.nextDouble(); switch(ch){ case "+":{ System.out.println(num1+"+"+num2+"="+(num1+num2)); break; } case "-":{ System.out.println(num1+"-"+num2+"="+(num1-num2)); break; } case "*":{ System.out.println(num1+"*"+num2+"="+(num1*num2)); break; } case "/":{ System.out.println(num1+"/"+num2+"="+(num1/num2)); break; } default :{ System.out.println("输入错误!"); break; } } } }
标签:scanner main blog code bre scan break system.in 数值
原文地址:http://www.cnblogs.com/lanseyitai1224/p/7011442.html