gpt4 book ai didi

java - 不兼容类型 : possible lossy conversion from double to int

转载 作者:行者123 更新时间:2023-11-30 06:15:13 27 4
gpt4 key购买 nike

<分区>

帮助?我不知道为什么会收到此错误。我在第 39 行:

term[1] = differentiate(Coeff[1], exponent[1]);

我该如何解决这个问题?

完整代码 list :

public class Calcprog {

public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int numTerms = 7;
double[] Coeff = new double[6];
double[] exponent = new double[6];
String[] term = new String[6];

System.out.println("Enter the number of terms in your polynomial:");
numTerms = input.nextInt();

while (numTerms > 6) {
if (numTerms > 6) {
System.out.println("Please limit the number of terms to six.");
System.out.println("Enter the number of terms in your polynomial:");
numTerms = input.nextInt();
}
}

for (int i = 1; i < numTerms + 1; i++) {
System.out.println("Please enter the coefficient of term #" + i + " in decimal form:");
Coeff[i] = input.nextDouble();
System.out.println("Please enter the exponent of term #" + i + " in decimal form:");
exponent[i] = input.nextDouble();
}
term[1] = differentiate(Coeff[1], exponent[1]);
}

public String differentiate(int co, int exp) {
double newco, newexp;
String derivative;
newexp = exp - 1;
newco = co * exp;
derivative = Double.toString(newco) + "x" + Double.toString(newexp);
return derivative;
}
}

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