当前位置:网站首页>第一次实践——计算器
第一次实践——计算器
2022-07-31 05:19:00 【Nauica】
import java.util.Scanner;
public class Method {
//计算器作业
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入需要计算的第一个数字");
double a=0;
double b=0;
String c="";
if (scanner.hasNextDouble()){
a=scanner.nextDouble();
}
System.out.println("请输入需要计算的第二个数字");
if (scanner.hasNextDouble()){
b=scanner.nextDouble();
}
System.out.println("请输入+-*/其中需要的算法");
if (scanner.hasNext()){
c=scanner.next();
}
if (c.equals("+")){
System.out.println(a+"+"+b+"="+(a+b));
}else if (c.equals("-")){
System.out.println(a+"-"+b+"="+(a-b));
}else if (c.equals("*")){
System.out.println(a+"*"+b+"="+(a*b));
}else if (c.equals("/")){
System.out.println(a+"/"+b+"="+(a/b));
}else{
System.out.println("请输入正确的符号");
}
scanner.close();
}
}
> 写的还是很好玩哒,用的比较粗俗的方法,还在继续学习,希望可以做出一个真正的计算器。
边栏推荐
猜你喜欢

会话和饼干,令牌

Learning and understanding of ROS service programming

crontab timing operation

PyTorch Study Notes 08 - Loading Datasets

国际站卖家大促攻略,只需要做好这几件事

【Rhapsody学习笔记】4:Relations

Websocket协议解析与QT代码示例

Session和Cookie,Token

能否更上一层楼?探究 CMake 争论

The content of the wangeditor editor is transferred to the background server for storage
随机推荐
滑动窗口法
DOM-DOM的介绍以及通过方法获取元素
VRchat_udon脚本介绍:傻瓜式教程教你如何实现VRchat地图的功能
a:自我介绍
Where can I find the private files set by myself?
2021-09-30
2021-09-30
四种常见的POST提交数据方式
cenos7配置IP,配置IP不生效
变更管理与 DevOps —— 二者同时进行吗?
C语言对文件的操作(完整版)
【源码笔记】痛苦来源于比较——什么是相等,hashCode() 和 equals(Object)
Pytorch Daily Practice - Predicting Surviving Passengers on the Titanic
ROS subscription to multiple topics time synchronization problem
ES6-Map和Set
常见网络攻击与防御方法
DSPE-PEG-COOH CAS: 1403744-37-5 Phospholipid-polyethylene glycol-carboxy lipid PEG conjugate
一种用QT实现即时通信软件表情发送与接收的思路
About iframe
概率论相关笔记