commit 935729e34e368a0e4382762433bf51b1341d2569 Author: 黄东海 <2544468477@qq.com> Date: Thu Aug 6 18:40:16 2020 +0800 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