0

Why I am not getting any output on my output screen? There should be a reversed array.

public class Main {
    static int[] reverse(int[] array)
    {
        int[] result =new int[array.length];
        for(int i=0,j=array.length-1;i<array.length;i++,j--)
        {
            result[j]=array[i];
        }
        return result;
    }


    public static void main(String[] args) {

        int[] newArray = {1,5,9,7,8,0,3,2};
        reverse(newArray);
    }
}
1
  • 2
    Store it in a variable and then print it or just directly print it. All you are doing it just returning it. Commented Feb 28, 2020 at 5:05

1 Answer 1

2

If you want to see output in your console, you need to send it to either the system's output stream (appropriate in this case), or the error stream.

int[] newArray = {1,5,9,7,8,0,3,2};
newArray = reverse(newArray);     // <- reuse the variable to save memory
System.out.println(Arrays.toString(newArray));
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.