gpt4 book ai didi

java - 错误 : incompatible types: String cannot be converted to int in Java

转载 作者:行者123 更新时间:2023-11-30 06:04:47 25 4
gpt4 key购买 nike

<分区>

我正在尝试从 cmd 获取参数并将该参数传递给方法 Fibonacci,但出现了一些错误。谁能告诉我为什么会出现此错误?

谢谢。

代码:

class fibo {

static void Fibonacci(int Total,int n1,int n2){

if(Total > 1){
int sum = n1 + n2;
System.out.print(sum + " ");
n1 = n2;
n2 = sum;
--Total;
Fibonacci(Total,n1,n2);
}
}

}

class main{

public static void main(String args[]){

fibo f = new fibo();
System.out.print(0 + " ");
System.out.print(1 + " ");
int Total = args[0];
int n1 = args[1];
int n2 = args[2];
f.Fibonacci(Total,n1,n2);


}
}

错误:

fibonacci.java:26: error: incompatible types: String cannot be converted to int
int Total = args[0];

fibonacci.java:27: error: incompatible types: String cannot be converted to int

int n1 = args[1];

fibonacci.java:28: error: incompatible types: String cannot be converted to int

int n2 = args[2];

3 errors

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