簡體   English   中英

返回數組方法賦值;

[英]return Array Method Assignment;

我正在嘗試返回一個數組方法是否可能?

public static void main(String [] args){
    int size;
    int [] myArray = new int [size];
    for(int i=0; i<size; i++){
        myArray[i]= returnArray(size)[i];
        System.out.println(myArray(i));
    }

}

private static int [] returnArray(int size){
    int arr = new int [size];
    for(int x=0; x<size; x++){
        arr[x]=x;
    }
    return arr;
}
int arr = new int [size];

應該:

int[] arr = new int [size];

和:

int [] myArray = new int [size];
for(int i=0; i<size; i++){
 myArray[i]= returnArray(size)[i];
 System.out.println(myArray(i));
}

可:

int [] myArray = returnArray(size);
for(int i=0; i<size; i++){
 System.out.println(myArray[i]);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM