gpt4 book ai didi

java:39: 找不到符号 symbol : 方法 exponent(double,int) else { return base * exponent(base, exponent - 1);}

转载 作者:行者123 更新时间:2023-12-02 07:17:14 24 4
gpt4 key购买 nike

import java.util.Scanner;

public class TaylorSin {

/* I am trying to approximate sin(x) using Maclaurin Series...
I am trying to get 1 term (1 Step Towards my approximation) the exponent divided by a factorial...
However I get stuck in the calculateExponent method...
Thank You in Advance! */

public static void main(String[] args) {

Scanner Keyboard = new Scanner(System.in);

double base; int exponent, n;

System.out.println();
System.out.println("Enter Base: ");
base = Keyboard.nextDouble();
System.out.println("Enter Exponent: ");
exponent = Keyboard.nextInt();
System.out.println("Enter n: ");
n = Keyboard.nextInt();
System.out.println();

System.out.println(calculateTerm(2.0, 4, 2));
}

public static int calculateFactorial(int n) {

int facto = 1;

for (int i = 1; i <= n; i++)

{facto = facto * i;}

return facto;

}

public static double calculateExponent(double base, int exponent) {

if(exponent == 0){return 1;}

else { return base * exponent(base, exponent - 1);} //The mistake occurs on that line...
}

public static double calculateTerm(double base, int exponent, int n) {

double term = (calculateExponent(base, exponent)/calculateFactorial(n));

return term;
}
}

最佳答案

而不是

else { return base * exponent(base, exponent - 1);} //The mistake occurs on that line...    

你是说

else { return base * calculateExponent(base, exponent - 1);} //The mistake occurs on that line... 

(即将exponent替换为calculateExponent)

方法名称exponent未定义。这就是错误消息试图告诉您的内容。

关于java:39: 找不到符号 symbol : 方法 exponent(double,int) else { return base * exponent(base, exponent - 1);},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14795327/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com