我尝试使用数组作为参数,但是当尝试将数组作为参数时,出现以下错误:
required: int,int[] found: int,int reason: actual argument int cannot be converted to int[] by method invocation conversion 2 errors
源代码:
public class utopian{
void height(int t,int[] n){
n = new int[100];
for (int i=0;i<t;i++){
int k = n[i];
if (k%2==0){
for(int j=0;j<=k;j=j+2){
int h=1;
h=h*2;
h=h+1;
}}
else{
for(int j=0;j<=k;j=j+2){
int h=1;
h=h*2;
h=h+1;
}
int h=h*2;
}
System.out.println(h);
}
}
}
--
public class Solution {
public static void main(String[] args) {
utopian heht = new utopian();
heht.height(2,{0,1})
}}
我想使用数组作为参数,但我不明白如何使用。
最佳答案
heht.height(2, new int[] {0,1})
但是,有些地方可以使用不太详细的符号,这可能会误导您:
int[] data = {0, 1};
关于java - java中如何将数组作为参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26216958/