Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7011423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:07:31+00:00 2026-05-27T22:07:31+00:00

I wrote code to reverse an integer array. Code is as shown below: public

  • 0

I wrote code to reverse an integer array. Code is as shown below:

public class ReverseArray {

    public static void main(String[] args) {
        try {
            int[] arr = new int[5];
            arr[0] = 1;
            arr[1] = 2;
            arr[2] = 3;
            arr[3] = 4;
            arr[4] = 5;
            for (int i = 0; i <= arr.length/2; i++)
                int temp = arr[0];
                arr[0] = arr[arr.length - i - 1];
                arr[arr.length - i - 1] = temp;
            }
            System.out.println(arr);

        } catch (Exception e) {
            System.out.println(e);
        }
    }
}

But it’s not reversing the array.. I’m getting following output.

 [I@3bad086a

I don’t see anything wrong with my logic.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:07:32+00:00Added an answer on May 27, 2026 at 10:07 pm

    That is printing out the reference to the array.
    If you print out the array one element at a time, you will see the reversed array.

    EDIT:
    Two more points.

    1. You’re using arr[0] when you intend to use arr[i].
    2. More insidious: you’re iterating too much. You only need to iterate until arr.length / 2. Since this is a homework question, I leave it to you to find out why; try printing out the intermediate results and explaining them.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

package testing.project; public class PalindromeThreeDigits { public static void main(String[] args) { int value
I wrote code to set permission of the folder. Function I developed was public
I wrote some code to read a file in my Java Servlet class. (I'm
I wrote a code sometime ago in which the object of ResultSet class res
I wrote following code...but i am getting Error like: Error 1 'LoginDLL.Class1.Login(string, string, string)':
I am reverse engineering some Java code into a class diagram. Now I'm wondering
I am trying to write code to reverse a string in place (I'm just
I was working on writing a small code snippet to reverse a string using
I wrote code below that is very similar to the accepted answer here .
I wrote some code with a lot of recursion, that takes quite a bit

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.