0

I am trying to return an array method is it possible ??

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;
}
2
  • Is this homework? If so, it should include the homework tag. Commented Apr 30, 2011 at 5:03
  • Have you even tried to compile it? Commented Apr 30, 2011 at 5:08

1 Answer 1

1
int arr = new int [size];

should be:

int[] arr = new int [size];

and:

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

can be:

int [] myArray = returnArray(size);
for(int i=0; i<size; i++){
 System.out.println(myArray[i]);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.