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,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);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue