From 935729e34e368a0e4382762433bf51b1341d2569 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E4=B8=9C=E6=B5=B7?= <2544468477@qq.com> Date: Thu, 6 Aug 2020 18:40:16 +0800 Subject: [PATCH] sj.java --- cal4.java | 31 +++++++++++++++++++++++++++++++ ex.java | 18 ++++++++++++++++++ log.java | 23 +++++++++++++++++++++++ main.java | 39 +++++++++++++++++++++++++++++++++++++++ sj.java | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 143 insertions(+) create mode 100644 cal4.java create mode 100644 ex.java create mode 100644 log.java create mode 100644 main.java create mode 100644 sj.java diff --git a/cal4.java b/cal4.java new file mode 100644 index 0000000..dd7d00e --- /dev/null +++ b/cal4.java @@ -0,0 +1,31 @@ +package calculator; + +import java.util.Scanner; + +public class cal4 { + public cal4() { + Scanner inScanner=new Scanner(System.in); + System.out.print("请输入第一位运算数:"); + double a=inScanner.nextInt(); + System.out.print("请输入第二位运算数:"); + double b=inScanner.nextInt(); + System.out.print("请输入将要运算的运算符:"); + String op=inScanner.next(); + char ch=op.charAt(0); + double sum=cala(a, b, ch); + System.out.println("结果为:"+sum); + } + + public static double cala(double x,double y,char op) { + switch (op) { + case '+': return x+y; + case '-': return x-y; + case '*': return x*y; + case '/': + if(y==0) return 0; + else return x/y; + default: + return x; + } + } +} \ No newline at end of file diff --git a/ex.java b/ex.java new file mode 100644 index 0000000..e85763a --- /dev/null +++ b/ex.java @@ -0,0 +1,18 @@ +package calculator; +import java.util.Scanner; +import java.lang.Math; +public class ex { + + public ex(){ + + Scanner input= new Scanner(System.in); + + System.out.print("请输入数字x:"); + int x=input.nextInt(); + double e=Math.E; + double n=Math.pow(e, x); + + + System.out.printf("结果为%.9f\n",n); + } +} diff --git a/log.java b/log.java new file mode 100644 index 0000000..c9c613b --- /dev/null +++ b/log.java @@ -0,0 +1,23 @@ +package calculator; +import java.util.Scanner; +public class log { + + public log() { + Scanner sc = new Scanner(System.in); + System.out.println("请输入底数a"); + double a = sc.nextDouble(); + System.out.println("请输入真数x"); + double x = sc.nextDouble(); + if(x>0&&a>0&&a!=1) + { + double result = log(a,x); + System.out.println("结果为:"+result); + } + else + System.out.println("errors "); + } + + public static double log(double a, double x){ + return Math.log(x) / Math.log(a); + } +} diff --git a/main.java b/main.java new file mode 100644 index 0000000..49f1dd0 --- /dev/null +++ b/main.java @@ -0,0 +1,39 @@ +package calculator; +import java.util.Scanner; +public class main { + + public static void main(String[] args) { + // TODO Auto-generated method stub + + + System.out.println("选择计算类型\n1、e~x\n2、logax\n3、+-×÷\n4、三角函数\n0、退出"); + Scanner inScanner = new Scanner(System.in); + + int flag=1; + while(flag==1) + { + int op1=inScanner.nextInt(); + switch(op1) { + case 1: + ex ex=new ex(); + break; + + case 2: + log log=new log(); + break; + + case 3: + cal4 cal=new cal4(); + break; + + case 4: + sj sj=new sj(); + break; + + case 0: flag=0; + } + } + System.out.println("计算结束"); +} + +} diff --git a/sj.java b/sj.java new file mode 100644 index 0000000..72458da --- /dev/null +++ b/sj.java @@ -0,0 +1,32 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package calculator; + +import java.util.*; +public class sj { + + + public sj() { + Scanner inScanner=new Scanner(System.in); + System.out.print("请输入一个运算(单位为度):"); + int a=inScanner.nextInt(); + System.out.print("接下来摁1是sin函数,2是cos函数,3是tan函数"); + int y=inScanner.nextInt(); + if(y==1){ + double x = Math.toRadians(a); + System.out.println(Math.sin(x)); + } + if(y==2) { + double b = Math.toRadians(a); + System.out.println(Math.cos(b)); + } + if(y==3){ + double c = Math.toRadians(a); + System.out.println(Math.tan(c)); + + } + } +} \ No newline at end of file