加减乘除计算器

 1 package com.main.cul;
 2 import java.util.Scanner;
 3 public class Demo {
 4     private static double result;
 5     public static void main(String[] argv){
 6     
 7     try{
 8         
 9         Scanner in=new Scanner(System.in);
10         System.out.print("请输入数字A:");
11         double numA=in.nextDouble();
12         
13         System.out.print("请选择操作+-*/(加减乘除):");
14         String strOper=in.next();
15         char  operate=strOper.charAt(0);
16         
17         System.out.print("请输入数字B:");
18         double numB=in.nextDouble();
19 
20         switch (operate) {
21         case '+':
22             result =numA+numB; 
23             break;
24         case '-':
25             result =numA-numB;  
26             break;
27         case '*':
28             result =numA*numB;  
29             break;
30         case '/':
31             result =numA/numB;  
32             break;
33         }
34     
35         System.out.print("结果为"+result);
36         
37     }catch (Exception e) {
38         // TODO: handle exception
39         e.printStackTrace();
40     }
41     }
42 }

 

posted @ 2016-03-26 15:10  吃猫的老鼠2222  阅读(276)  评论(2编辑  收藏  举报