Java 浅做计算机
2022/5/10 20:00:26
本文主要是介绍Java 浅做计算机,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
package www.nihao; import java.util.Scanner; public class counter { public static void main(String[] args) { Scanner scanner=new Scanner(System.in); System.out.println("请输入两个操作数:"); int number1 = scanner.nextInt(); int number2 = scanner.nextInt(); System.out.println("请选择你要计算的法则:"); System.out.println("1.加法"); System.out.println("2.减法"); System.out.println("3.乘法"); System.out.println("4.除法"); int rule = scanner.nextInt(); switch (rule) { case 1: System.out.println(add(number1, number2)); break; case 2: System.out.println(minus(number1, number2)); break; case 3: System.out.println(multiply(number1, number2)); break; case 4: System.out.println(division(number1, number2)); break; default: return;} scanner.close(); } public static int add(int a,int b){ int sum; sum=a+b; return sum; } public static int minus(int a,int b){ int sum; sum=a-b; return sum; } public static int multiply(int a,int b){ int sum; sum=a*b; return sum; } public static int division(int a,int b){ int sum; sum=a/b; return sum; } }
这篇关于Java 浅做计算机的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-26Mybatis官方生成器资料详解与应用教程
- 2024-11-26Mybatis一级缓存资料详解与实战教程
- 2024-11-26Mybatis一级缓存资料详解:新手快速入门
- 2024-11-26SpringBoot3+JDK17搭建后端资料详尽教程
- 2024-11-26Springboot单体架构搭建资料:新手入门教程
- 2024-11-26Springboot单体架构搭建资料详解与实战教程
- 2024-11-26Springboot框架资料:新手入门教程
- 2024-11-26Springboot企业级开发资料入门教程
- 2024-11-26SpringBoot企业级开发资料详解与实战教程
- 2024-11-26Springboot微服务资料:新手入门全攻略