Java:整数声明中的参数列表错误
我在第18行得到一个错误,它描述:Java:整数声明中的参数列表错误,java,class,methods,int,declaration,Java,Class,Methods,Int,Declaration,我在第18行得到一个错误,它描述: HelloWorld.java:18: error: method calcThirdChance in class HelloWorld cannot be applied to given types; int t3 = calcThirdChance(t1+t2); ^ required: int,int found: int reason: actual and formal argument lists d
HelloWorld.java:18: error: method calcThirdChance in class HelloWorld cannot be applied to given types;
int t3 = calcThirdChance(t1+t2);
^
required: int,int
found: int
reason: actual and formal argument lists differ in length
这对我来说没有什么意义,因为方法calcThirdChance返回一个int,而我在该行中只声明了一个int,因此我不知道为什么它需要2个int,这据说是错误的原因
public class HelloWorld{
public static void main(String []args){
System.out.println(simMin(70,80));
}
public static int calcThirdChance(int t1, int t2){
int c;
c = -1*(t1+t2);
double finalsend;
finalsend = Math.pow(2.71, c/100)*2;
finalsend*=150;
return (int)finalsend;
}
public static int simMin(int t1, int t2){
int t3 = calcThirdChance(t1+t2);
int total=t1+t2+t3;
int play = 50;
if(play<=t1){
return t1;
}
else if(play<=t1+t2){
return t2;
}
else{
return t3;
}
}
}
公共类HelloWorld{
公共静态void main(字符串[]args){
系统输出println(simMin(70,80));
}
公共静态int calcThirdChance(int t1,int t2){
INTC;
c=-1*(t1+t2);
双终点;
最终结果=数学功率(2.71,c/100)*2;
finalsend*=150;
返回(int)finalsend;
}
公共静态int simMin(int t1,int t2){
int t3=calcThirdChance(t1+t2);
总积分=t1+t2+t3;
int play=50;
if(playcalcThirdChance
接受2个参数
int t3 = calcThirdChance(t1, t2);
您得到的错误与calcThirdChance
的返回类型无关
您正在向方法传递一个参数:
calcThirdChance(t1+t2);
你需要通过两个考试:
calcThirdChance(t1,t2);
顺便说一句,看到calcThirdChance(int t1,int t2)
只需要它接收到的参数之和,您可以将其更改为:
public static int calcThirdChance(int t)
{
int c;
c = -1*t;
double finalsend;
finalsend = Math.pow(2.71, c/100)*2;
finalsend*=150;
return (int)finalsend;
}
这将使调用calcThirdChance(t1+t2)
有效。
calcThirdChance(t1+t2);
传递t1+t2的结果(一个值),但您的方法需要两个值。我想您需要
calcThirdChance(t1, t2); // <-- a comma
calcThirdChance(t1,t2);//但是只返回1,我需要calcThirdChance返回的值,该值仅为1 int。t1和t2已经存在declared@user1832697你可以在t3中找到它。哦,谢谢,我的眼镜丢了,我看不清楚