java 实现一个简易计算器

import java.util.Scanner;
public class Test {
public static void main(String[] args) { count();
} public static void count() {
Scanner input1 = new Scanner(System.in);
System.out.println("输入一个数");
double a = input1.nextDouble();
while (true) {
Scanner input3 = new Scanner(System.in);
System.out.println("提示:请输入您的操作");
System.out.println("+");
System.out.println("-");
System.out.println("*");
System.out.println("/");
System.out.println("F:退出");
String str = input3.nextLine();
char chr = str.toCharArray()[0];
switch (chr) {
case '+':
a = add(a);
System.out.println("当前结果为:"+a);
break;
case '-':
a = subtrace(a);
System.out.println("当前结果为:"+a);
break;
case '*':
a = ride(a);
System.out.println("当前结果为:"+a);
break;
case '/':
a = except(a);
System.out.println("当前结果为:"+a);
break;
case 'F':
System.out.println("结果:" + a);
System.exit(-1); default:
System.out.println("操作错误!");
break;
}
}
} public static double add(double a) {
Scanner input2 = new Scanner(System.in);
System.out.println("输入一个数");
double b = input2.nextDouble();
return (a + b);
} public static double subtrace(double a) {
Scanner input2 = new Scanner(System.in);
System.out.println("输入一个数");
double b = input2.nextDouble();
return (a - b); } public static double ride(double a) {
Scanner input2 = new Scanner(System.in);
System.out.println("输入一个数");
double b = input2.nextDouble();
return a * b; } public static double except(double a) {
Scanner input2 = new Scanner(System.in);
System.out.println("输入一个数");
double b = input2.nextDouble();
return a / b; }
}
上一篇:C#窗体如何通过keybd_event()函数模拟键盘按键(组合键)产生事件


下一篇:不用winio直接用c#函数实现模拟键盘