计算器的简单实现
java实现简单的计算器功能
1 package com.su.jichu; 2 3 import com.sun.xml.internal.ws.api.model.wsdl.WSDLOutput; 4 5 import java.util.Scanner; 6 7 public class jsq { 8 public static void main(String[] args) { 9 Scanner scanner = new Scanner(System.in); 10 double a = scanner.nextInt(); 11 char c = scanner.next().charAt(0); //将获取到的第一个char类型赋值给b 12 double b = scanner.nextInt(); 13 System.out.println(a+""+""+c+""+b); 14 switch (c){ 15 case '+' : jia(a,b); break; 16 case '-': jian(a,b); break; 17 case '*' : chen(a,b); break; 18 case '/' : chu(a,b); break; 19 default: 20 System.out.println("输入有误!!"); 21 break; 22 } 23 } 24 public static void jia(double a,double b) 25 { 26 double sum =a + b; 27 System.out.println("sum="+sum); 28 29 } 30 public static void jian(double a,double b) 31 { 32 double sum=0; 33 if(a>b){ 34 sum=a-b; 35 }else{ 36 sum=-(b-a); 37 } 38 System.out.println("sum="+sum); 39 40 } 41 public static void chen(double a,double b) 42 { 43 double sum = a*b; 44 System.out.println("sum="+sum); 45 46 } 47 public static void chu(double a,double b) 48 { 49 double sum = a /b; 50 System.out.println("sum="+sum); 51 52 } 53 }