|
|
@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
package Hello;
|
|
|
|
|
|
|
|
import java.io.*;
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
import java.math.*;
|
|
|
|
|
|
|
|
public class Hello{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static double mypow(double e,double x) {
|
|
|
|
|
|
|
|
double ans=Math.pow(e, x);
|
|
|
|
|
|
|
|
return ans;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static double mylog(double a,double x) {
|
|
|
|
|
|
|
|
double ans=Math.log(x)/Math.log(a);
|
|
|
|
|
|
|
|
return ans;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static double myadd(double a,double b) {
|
|
|
|
|
|
|
|
return a+b;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static double mysub(double a,double b) {
|
|
|
|
|
|
|
|
return a-b;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static double mymultiply(double a,double b) {
|
|
|
|
|
|
|
|
return a*b;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static double mydivide(double a,double b) {
|
|
|
|
|
|
|
|
return a/b;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static double mysin(double x) {
|
|
|
|
|
|
|
|
return Math.sin(x);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static double mycos(double x) {
|
|
|
|
|
|
|
|
return Math.cos(x);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static double mytan(double x) {
|
|
|
|
|
|
|
|
return Math.tan(x);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String args[]) {
|
|
|
|
|
|
|
|
Scanner cin=new Scanner(System.in);
|
|
|
|
|
|
|
|
System.out.printf("功能表:\n说明:输入add a b执行a+b\n"
|
|
|
|
|
|
|
|
+ "pow e x\nlog a x\nadd a b\nsub a b\nmultiply a b\n"
|
|
|
|
|
|
|
|
+ "divide a b\nsin x\ncos x\ntan x\nquit:退出\n");
|
|
|
|
|
|
|
|
while (cin.hasNext()) {
|
|
|
|
|
|
|
|
String op=cin.next();
|
|
|
|
|
|
|
|
double a,b,ans=0;
|
|
|
|
|
|
|
|
switch(op) {
|
|
|
|
|
|
|
|
case "pow":
|
|
|
|
|
|
|
|
a=cin.nextDouble();
|
|
|
|
|
|
|
|
b=cin.nextDouble();
|
|
|
|
|
|
|
|
ans=mypow(a,b);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "log":
|
|
|
|
|
|
|
|
a=cin.nextDouble();
|
|
|
|
|
|
|
|
b=cin.nextDouble();
|
|
|
|
|
|
|
|
ans=mylog(a,b);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "add":
|
|
|
|
|
|
|
|
a=cin.nextDouble();
|
|
|
|
|
|
|
|
b=cin.nextDouble();
|
|
|
|
|
|
|
|
ans=myadd(a,b);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "sub":
|
|
|
|
|
|
|
|
a=cin.nextDouble();
|
|
|
|
|
|
|
|
b=cin.nextDouble();
|
|
|
|
|
|
|
|
ans=mysub(a,b);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "multiply":
|
|
|
|
|
|
|
|
a=cin.nextDouble();
|
|
|
|
|
|
|
|
b=cin.nextDouble();
|
|
|
|
|
|
|
|
ans=mymultiply(a,b);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "divide":
|
|
|
|
|
|
|
|
a=cin.nextDouble();
|
|
|
|
|
|
|
|
b=cin.nextDouble();
|
|
|
|
|
|
|
|
while(b==0) {
|
|
|
|
|
|
|
|
System.out.printf("除数不能为0,请重新输入除数!\n");
|
|
|
|
|
|
|
|
b=cin.nextDouble();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ans=mydivide(a,b);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "sin":
|
|
|
|
|
|
|
|
a=cin.nextDouble();
|
|
|
|
|
|
|
|
ans=mysin(a);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "cos":
|
|
|
|
|
|
|
|
a=cin.nextDouble();
|
|
|
|
|
|
|
|
ans=mycos(a);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "tan":
|
|
|
|
|
|
|
|
a=cin.nextDouble();
|
|
|
|
|
|
|
|
ans=mytan(a);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
System.out.println("已退出计算器\n");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
System.out.printf("%f\n",ans);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cin.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|