Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Code is not working. Please fix and share screenshots of output thank you import java.util.Arrays; /* * * This program takes an array of integers,

Code is not working. Please fix and share screenshots of output thank you

import java.util.Arrays;
/*
*
* This program takes an array of integers, reverses the elements and stores them in a new array
*
*/
public class ReverseElements
{
/**
Reverses an array.
@param data - the input array
@return an array with the elements of data in reverse order
*/
public static int[] reverse(int[] data)
{
  //-----------Start below here. To do: approximate lines of code = 6
  //
 int i , t, n= data.length;
for ( i = 0; i < n/2 ; i++){
t= data[i] ;
data[i] = data[n - i - 1] ;
data[n - i - 1 ] = t ;
}
return data;
}
 
  //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}


public static void main(String[] args)
{
int[] data = { 1, 4, 9, 16, 9, 7, 4, 9, 11 };
int[] reversed = reverse(data);
for (int i = 0; i < reversed.length; i++)
{
System.out.print(reversed[i] + " ");
}
System.out.println();
System.out.println("Expected:n11 9 4 7 9 16 9 4 1");
}
}

Step by Step Solution

3.42 Rating (171 Votes )

There are 3 Steps involved in it

Step: 1

Note just delete one ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Algorithms

Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest

3rd edition

978-0262033848

More Books

Students also viewed these Programming questions

Question

List some common reasons for redesigning layouts.

Answered: 1 week ago