当前位置:网站首页>第一次实践——计算器
第一次实践——计算器
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();
}
}
> 写的还是很好玩哒,用的比较粗俗的方法,还在继续学习,希望可以做出一个真正的计算器。
边栏推荐
- Remote file xxx is mapped to the local path xxx and can‘t be found. You can continue debugging....
- Unity加载GIf动画
- Log jar package conflict, and its solution
- 堆和栈的区别
- 国际站卖家大促攻略,只需要做好这几件事
- Picture-in-Picture API in the browser
- Session和Cookie,Token
- Webrtc从理论到实践三:角色
- Attention based ASR(LAS)
- Virtual machine view port number process
猜你喜欢
DOM操作-案例:切换背景图片
MySQL free installation download and configuration tutorial
ImportError: cannot import name ‘Xxxx‘ from partially initialized module ‘xx.xx.xx‘
box-shadow related properties
Rejection sampling note
Four common ways of POST to submit data
Unity转微信小游戏与JS交互
UR3机器人运动学分析之逆运动学分析
Webrtc从理论到实践一:初识
Pytorch study notes 7 - processing input of multi-dimensional features
随机推荐
衡量 DevOps 成功与否的重要度量指标
IDEA控制台不能输入信息的解决方法
钉钉企业内部-H5微应用开发
UR3机器人运动学分析之逆运动学分析
测试CSDN积分需求
C语言结构体(必须掌握版)
IDEA overview and installation and debugging
自己设置的私密文件,在哪找
概率论相关笔记
2021-09-30
会话和饼干,令牌
Pytorch learning notes 09 - multiple classification problem
Incredibuild 宣布支持 Yocto
Attention based ASR(LAS)
什么样的人不适合入行编程?你真的适合学习编程吗?
Session和Cookie,Token
四种常见的POST提交数据方式
力扣151. 颠倒字符串中的单词
Tensorflow steps on the pit while using it
力扣.三数之和/四数之和