标签:code new ati png div ann .com ext count
计算器功能:简易的实现两数之间的加减乘除
程序代码:
counter类:
package com.counter; public class Counter { public void count(String fuHao,double a , double b){ switch (fuHao){ case "+": double sum1 = a + b; System.out.println("两数之和为:"+sum1); break; case "-": double sum2 = a - b; System.out.println("两数之差为:"+sum2); break; case "*": double sum3 = a * b; System.out.println("两数之积为:"+sum3); break; case "/": double sum4 = a / b; System.out.println("两数之商为:"+sum4); break; } } }
主程序代码:
package com.counter; import java.util.Scanner; public class CounterTest { public static void main(String[] args) { Counter count = new Counter(); Scanner s = new Scanner(System.in); System.out.println("请输入两个要计算的数:"); double a = s.nextDouble(); double b = s.nextDouble(); System.out.println("请输入运算符:"); String fuHao = s.next(); count.count(fuHao,a,b); } }
运行结果:
标签:code new ati png div ann .com ext count
原文地址:https://www.cnblogs.com/yangwenxiang/p/10259058.html