Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a java program that calls a method called reverse4 that accepts an ArrayList of integer values as a parameter and reverses each successive sequence

Write a java program that calls a method called reverse4 that accepts an ArrayList of integer values as a parameter and reverses each successive sequence of four values in the list. If the list has extra values that are not part of a sequence of four, those values are unchanged. For example if a list stores values [10, 13, 2, 8, 7, 90, -1, 2, 4, 5], after the call the list should store the values [8, 2, 13, 10, 2, -1, 90, 7, 4, 5]. The first sequence of four (10, 13, 2, 8) has been reversed to (8, 2, 13, 10). The second sequence (7, 90, -1, 2) has been reversed to (2, -1, 90, 7) and so on. Notice that 4 and5 are unchanged because they were not part of a sequence of four values. Print the array before the call and after the call.

import java.util.*; public class Reverse4 { public static void main(String[] args) { ArrayList list = new ArrayList(); list.add(10); list.add(13); list.add(2); list.add(8); list.add(7); list.add(90); list.add(-1); list.add(2); list.add(4); list.add(5); System.out.println(list.toString()); reverse4(list); System.out.println(list.toString()); }

*Insert method code here*

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Pro SQL Server Wait Statistics

Authors: Enrico Van De Laar

1st Edition

1484211391, 9781484211397

More Books

Students also viewed these Databases questions