Calculator.java

master
韦光照 4 years ago
parent affeb40183
commit 47b32b4b28

@ -0,0 +1,36 @@
package guangzhaowei;
import java.util.Scanner;
public class Calculator{
public static void main(String[] args){
char e;
boolean f=true;
Scanner in = new Scanner(System.in);
while(f){
System.out.println("请选择运算方式:+、-、*、/、^、"
+ "对数l三角函数s或者退出e");
e=in.next().charAt(0);
switch(e){
case '+':case '-':case '*':case '/':
Easy.c();
break;
case '^':
Exp.pow();
break;
case 'l':
Logarithm.log();
break;
case 's':
Triangle.angle();
break;
case 't':
f=false;
}
}
}
}

@ -0,0 +1,15 @@
package guangzhaowei;
import java.util.Scanner;
public class Logarithm {
public static void log() {
Scanner sc= new Scanner(System.in);
System.out.println("请输入对数:");
double base=sc.nextDouble();
System.out.println("请输入真数:");
double value=sc.nextDouble();
double result=Math.log(value)/Math.log(base);
System.out.println("运算结果是"+result);
}
}

@ -0,0 +1,35 @@
package guangzhaowei;
import java.util.Scanner;
public class Triangle {
public static void angle(){
Scanner sc= new Scanner(System.in);
System.out.println("三角函数类型:");
String b=sc.next();
System.out.println("数值:");
double a=sc.nextDouble();
double c = Math.toRadians(a);
if (a % 180 == 0 && b.equals("sin")) {
System.out.println("运算结果是0");
}
if (a % 90 == 0 && a % 180 != 0 && b.equals("cos")) {
System.out.println("运算结果是0");
}
switch (b) {
case "cos":
System.out.println("运算结果是"+Math.cos(c));
break;
case "sin":
System.out.println("运算结果是"+Math.sin(c));
break;
case "tan":
System.out.println("运算结果是"+Math.tan(c));
break;
case "cot":
System.out.println("运算结果是"+1 / Math.tan(c));
break;
}
}
}
Loading…
Cancel
Save