Which reverses the order of an arrays elements

Assignment Help JAVA Programming
Reference no: EM131585563

Write a method named, reverse, which reverses the order of an array's elements without creating another array.

The header for the method, reverse, is:

void reverse( int arr() ){

where arr is an array containing any number of integer elements.

For example, if the array is {6, 4, 9, 1, 7) BEFORE calling reverse, then the array should be {7, 1, 9, 4, 6) AFTER calling reverse. Your code should work for any length of integer array containing any values. Your reverse method should not do any keyboard input and no printing to the console.

You should write the method, reverse, in a class named, FinalExam. In the FinalExam class you must also include a main method that tests the method, reverse. The main method may do console output, but does not need any keyboard input. Arrays created in main for use in testing the reverse method should be created using static initialization as in the example below. Here are four tests you should run from the main method by calling the reverse method:

1. Pass an array with 10 elements and then verify the array elements are reversed upon returning from the method, reverse. Here is an example of doing this:
// create the array to test
into myArray = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int() myArrayRev = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }; reverse( myArray );
if( Arrays.equals( myArray, myArrRev ) )
System.out.println( "reverse worked for 10 elements." );

NOTE: The Arrays class may be found in the java.util package.

2. Pass an array with 9 elements and then verify the array elements are reversed upon returning from the method, reverse.

3. Pass an array with 1 element and then verify the array element is unchanged upon returning from the method, reverse.

4. Pass an array with 0 elements and then verify the array is unchanged reversed upon returning from the method, reverse.

Attachment:- ArrayCheck.rar

Reference no: EM131585563

Questions Cloud

Determine the utilization of its products or services : Outline a strategy for the health care provider you selected to determine the utilization of its products or services.
What is your worst team experience : What is your worst team experience? Why was it so bad? What could have been done to make it a more positive experience?
What would you do to practice the new skills and why : If you were Doug in the case above, what would you do to practice the new skills, and why? Any current topic or article related to penetration techniques.
Find a perfect matching for each graph : Examine Figure, which shows three trees. If possible, find a perfect matching in each tree; if not, explain why no perfect matching exists.
Which reverses the order of an arrays elements : Write a method named, reverse, which reverses the order of an array's elements without creating another array - elements and then verify the array elements
Essential component to organizational life these days : Teamwork is a common and essential component to organizational life these days. Pretty much every organization will utilize teamwork in some way.
Create a binary decision tree : Create a binary decision tree that determines which of the current US coins (penny, nickel, dime, quarter, half-dollar, and dollar) has been offered to a robot.
Comment on theory influences nursing practice : As Pearson, Vaughn, and Fitzgerald (2005) state, a model is not the real thing but comes as close as possible.
What kind of binary search tree for the micro-dictionary : Placing baa at the root, draw a binary search tree for the micro-dictionary aaa, ab, baa, baba.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Write a reference class called ctatrain

writing a reference class that consist of the 2nd and 3rd instance variables below. my class should consist of an array of values in the 2nd instance variable

  Practice involves creating an algorithm

Practice involves creating an algorithm. An algorithm (pronounced AL-go-rith-um) is a procedure or formula for solving a problem. We will see in future weeks how the detailed steps of this type of procedure relate to pseudocode and, in general, to th..

  Design an object hierarchy

Design an object hierarchy and design your own UML class diagram to reflect the classes and relationship required by your program.

  List data structures to be used in solution

write a program that will prompt the user for an input file name to read from. The Input file will consist of records made up of first name, last name and an account balance of individuals and store the individuals in an ArrayList.

  Write a recursive method to reverse a string.

write a recursive method to reverse a string. Explain why you would not normally use recursion to solve this problem?

  Write a program to compute the cumulative gpa

This program will compute the cumulative GPA based on user input.  This program will use dialog boxes with the JOptionPane class as well as the console to send/receive information to/from the user.

  Create an interpreter class with a static method

Create an interpreter class with a static method interpreter that takes in two strings as arguments: the first for the name of input file

  Create a java class called samearraysexception

Create a Java class called SameArraysException that extends the Exception class.

  Write a java program that calculates and displays the result

Write a Java program that calculates and displays the results of addition, subtraction, multiplication, division, modulus, bitwise &, or bitwise | operation on two integer values input by the user.

  Create a third string consisting of the first half of string

Show the length of both strings - Create a third string consisting of the first half of string (1) and the second half of string.

  Write a java program to read a number up to fifteen digits

Write a java program and pseudocode to read a number up to 15 digits long or a date (dd/mm/yyyy). The program should distinguish numbers from input date, and prints them in alphabetic spelling form.

  Extend the java defined hashmap class

Your goal is to extend the java defined HashMap class to add the ability to store multiple objects. To do this, you will edit MultiHashMap.java to both add new methods and override two methods from HashMap.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd