用javaFX编写一个简单的计算器
1个回答
2016-06-16 · 做真实的自己 用良心做教育
千锋教育
千锋教育专注HTML5大前端、JavaEE、Python、人工智能、UI&UE、云计算、全栈软件测试、大数据、物联网+嵌入式、Unity游戏开发、网络安全、互联网营销、Go语言等培训教育。
向TA提问
关注
展开全部
public static void main(String[] args) {
System.out.println("请输入第一个数:");
Scanner scanner1 = new Scanner(System.in);
double input1 = Double.parseDouble(scanner1.nextLine());
System.out.println("请输入符号:");
Scanner scanner3 = new Scanner(System.in);
String method = scanner3.nextLine();
System.out.println("请输入第二个数:");
Scanner scanner2 = new Scanner(System.in);
double input2 = Double.parseDouble(scanner2.nextLine());
double result = 0;
if (method.equals("+")) {
result = input1 + input2;
System.out.println("运行结果为:");
System.out.print(result);
}
if (method.equals("-")) {
result = input1 - input2;
System.out.println("运行结果为:");
System.out.print(result);
}
if (method.equals("*")) {
result = input1 * input2;
System.out.println("运行结果为:");
System.out.print(result);
}
if (method.equals("/")) {
result = input1 / input2;
System.out.println("运行结果为:");
System.out.print(result);
} else {
System.out.println("无此运算符");
}
}
System.out.println("请输入第一个数:");
Scanner scanner1 = new Scanner(System.in);
double input1 = Double.parseDouble(scanner1.nextLine());
System.out.println("请输入符号:");
Scanner scanner3 = new Scanner(System.in);
String method = scanner3.nextLine();
System.out.println("请输入第二个数:");
Scanner scanner2 = new Scanner(System.in);
double input2 = Double.parseDouble(scanner2.nextLine());
double result = 0;
if (method.equals("+")) {
result = input1 + input2;
System.out.println("运行结果为:");
System.out.print(result);
}
if (method.equals("-")) {
result = input1 - input2;
System.out.println("运行结果为:");
System.out.print(result);
}
if (method.equals("*")) {
result = input1 * input2;
System.out.println("运行结果为:");
System.out.print(result);
}
if (method.equals("/")) {
result = input1 / input2;
System.out.println("运行结果为:");
System.out.print(result);
} else {
System.out.println("无此运算符");
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询