master
黄东海 4 years ago
commit 935729e34e

@ -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;
}
}
}

@ -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);
}
}

@ -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);
}
}

@ -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("计算结束");
}
}

@ -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));
}
}
}
Loading…
Cancel
Save