当前位置:网站首页>Simple code implementation of addition, subtraction, multiplication and division calculator
Simple code implementation of addition, subtraction, multiplication and division calculator
2022-06-12 14:26:00 【Happy happy】
Addition, subtraction, multiplication and division calculator simple code implementation
Thinking is introduced : Use circulation and Switch Make selection operator , Compiling .
Code example
package method;
import java.util.Scanner;
public class Demo06 {
public static void main(String[] args) {
double result=0;
Scanner scanner = new Scanner(System.in);
while (true){
System.out.print(" Please enter the first number to be calculated :");
double first = scanner.nextDouble();
System.out.print(" Please enter the operator to evaluate :");
String fuhao = scanner.next();
System.out.print(" Please enter the second number to be calculated :");
double second = scanner.nextDouble();
switch (fuhao){
case "+":
result=first + second;
System.out.println(" The result is :"+result);
continue;
case "-":
result=first - second;
System.out.println(" The result is :"+result);
continue;
case "*":
result=first * second;
System.out.println(" The result is :"+result);
continue;
case "/":
result=first / second;
System.out.println(" The result is :"+result);
continue;
default:
System.out.println(" Please enter the correct operation symbol !!!!");
}
}
}
}
Console display
D:\apps\jdk8\bin\java.exe "-javaagent:E:\javanote\IntelliJ IDEA Community Edition 2021.1\lib\idea_rt.jar=63184:E:\javanote\IntelliJ IDEA Community Edition 2021.1\bin" -Dfile.encoding=UTF-8 -classpath D:\apps\jdk8\jre\lib\charsets.jar;D:\apps\jdk8\jre\lib\deploy.jar;D:\apps\jdk8\jre\lib\ext\access-bridge-64.jar;D:\apps\jdk8\jre\lib\ext\cldrdata.jar;D:\apps\jdk8\jre\lib\ext\dnsns.jar;D:\apps\jdk8\jre\lib\ext\jaccess.jar;D:\apps\jdk8\jre\lib\ext\jfxrt.jar;D:\apps\jdk8\jre\lib\ext\localedata.jar;D:\apps\jdk8\jre\lib\ext\nashorn.jar;D:\apps\jdk8\jre\lib\ext\sunec.jar;D:\apps\jdk8\jre\lib\ext\sunjce_provider.jar;D:\apps\jdk8\jre\lib\ext\sunmscapi.jar;D:\apps\jdk8\jre\lib\ext\sunpkcs11.jar;D:\apps\jdk8\jre\lib\ext\zipfs.jar;D:\apps\jdk8\jre\lib\javaws.jar;D:\apps\jdk8\jre\lib\jce.jar;D:\apps\jdk8\jre\lib\jfr.jar;D:\apps\jdk8\jre\lib\jfxswt.jar;D:\apps\jdk8\jre\lib\jsse.jar;D:\apps\jdk8\jre\lib\management-agent.jar;D:\apps\jdk8\jre\lib\plugin.jar;D:\apps\jdk8\jre\lib\resources.jar;D:\apps\jdk8\jre\lib\rt.jar;E:\javanote\out\production\Hello method.Demo06
Please enter the first number to be calculated :5
Please enter the operator to evaluate :/
Please enter the second number to be calculated :5
The result is :1.0
Please enter the first number to be calculated :5
Please enter the operator to evaluate :+
Please enter the second number to be calculated :5
The result is :10.0
Please enter the first number to be calculated :5
Please enter the operator to evaluate :-
Please enter the second number to be calculated :5
The result is :0.0
Please enter the first number to be calculated :5
Please enter the operator to evaluate :*
Please enter the second number to be calculated :5
The result is :25.0
Please enter the first number to be calculated :5
Please enter the operator to evaluate :5
Please enter the second number to be calculated :5
Please enter the correct operation symbol !!!!
Please enter the first number to be calculated :
边栏推荐
- chapter19 Allocation
- Ppt cannot be opened, always prompt how to fix it
- Design of PLC intelligent slave station based on PROFIBUS DP protocol
- Dynamic search advertising intelligent search for matching keywords
- How to realize the bidding strategy that pays more attention to transformation in the company's operation Google sem
- Recursive summary of learning function
- What is automatic bidding? What are its advantages?
- Wait function in SystemC
- C secret script Chapter 3 (detailed explanation of string function) (Section 1)
- Tcp/ip network communication knowledge record
猜你喜欢

Perfect ending | detailed explanation of the implementation principle of go Distributed Link Tracking

Redis core configuration and advanced data types

对于跨境电商,更侧重收入的出价策略 —Google SEM

Démontage et modification de la machine publicitaire - décompression amateur

En langage C, la fonction principale appelle une autre fonction et assemble le Code pour comprendre

拆改廣告機---業餘解壓

公司运营中更注重转化的出价策略,如何实现? —Google sem

Leetcode 2176. 统计数组中相等且可以被整除的数对

Dismantle and modify the advertising machine - Amateur decompression

正点原子STM32F429核心板的插座型号
随机推荐
Brush one question every day /537 Complex multiplication
QA of some high frequency problems in oauth2 learning
Communication flow analysis
Alicloud development board vscode development environment setup
Huawei equipment is configured with H virtual private network
SystemC learning materials
【OCR】AspriseOCR C# 英文、數字識別(中文不行)
工业机械臂(机器人)视觉定位引导系统
C secret arts script Chapter 5 (structure) (Section 2)
SystemC:SC_ Thread and SC_ METHOD
C magic skill Chapter 4 (detailed explanation of memory function)
Player actual combat 25 unpacking module add close
Lua tvalue structure
浅谈中国程序员为什么要跳槽?
Introduction to QT reflection mechanism and signal slot mechanism
Word insert picture blocked by text
C secret arts script Chapter 2 (detailed explanation of pointers) (Section 3)
[early knowledge of activities] list of recent activities of livevideostack
C secret arts script Chapter 5 (paragraph) (Section 3)
Player actual combat 21 audio and video synchronization