Write a method swapArrayEnds() that swaps the first and last elements of its array parameter. Ex: sortArray = {10, 20, 30, 40} becomes {40, 20, 30, 10}.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

import java.util.Scanner;

public class ModifyArray {

   public swapArrayEnds(10, 20, 30, 40) {
       for (i = 0; i < (arrVals.length / 2); ++i) {
         tempValue = arrVals[i]; // Do swap                              //*please fix code//
         arrVals[i] = arrVals[arrVals.length - 1 - i];
         arrVals[arrVals.length - 1 - i] = tempValue;
   

  Write a method swapArrayEnds() that swaps the first and last elements of its array parameter. Ex: sortArray = {10, 20, 30, 40} becomes {40, 20, 30, 10}.

public static void main (String [] args) {
      Scanner scnr = new Scanner(System.in);
      int numElem = 4;
      int[] sortArray = new int[numElem];
      int i;
      int userNum;

      for (i = 0; i < sortArray.length; ++i) {
         sortArray[i] = scnr.nextInt();
      }

      swapArrayEnds(sortArray);

      for (i = 0; i < sortArray.length; ++i) {
         System.out.print(sortArray[i]);
         System.out.print(" ");
      }
      System.out.println("");
   }
}

CTU Class Homepage.
H
zy Section 4.4 - CS 226T: Java Progra X
✰ learn.zybooks.com/zybook/CS226-2204A-03-2204A/chapter/4/section/4
=zyBooks My library > CS 226T: Java Programming home > 4.4: Array parameters
Run
Thank you. Your reservation is co X
ART
Common student error
Your code used a for loop. Instead, swapping the first and last elements requires a temporary variable, not a loop.
Failed to compile
ModifyArray.java:5: error: invalid method declaration; return type required
public swapArrayEnds (10, 20, 30, 40) {
Print - Your Confirmed Reservatic X b Answered: 4.2.3: Method definiti X
ModifyArray.java:5: error: illegal start of type
public swapArrayEnds (10, 20, 30, 40) {
3 errors
ModifyArray.java:12: error: illegal start of expression
public static void main (String [] args) {
How was this section?
Note: Although the reported line number is in the uneditable part of the code, the error actually exists in your code. Tools often
don't recognize the problem until reaching a later line.
Provide feedback
zyBooks catalog
Activity summary for assignment: Unit 4 Interactive Assignment
Due: 10/31/2022, 3:59 PM -08
Feedback?
? Help/FAQ
70 %
70% submitted to
Stacey Queen
X
:
9:11 AM
8/30/2022
Transcribed Image Text:CTU Class Homepage. H zy Section 4.4 - CS 226T: Java Progra X ✰ learn.zybooks.com/zybook/CS226-2204A-03-2204A/chapter/4/section/4 =zyBooks My library > CS 226T: Java Programming home > 4.4: Array parameters Run Thank you. Your reservation is co X ART Common student error Your code used a for loop. Instead, swapping the first and last elements requires a temporary variable, not a loop. Failed to compile ModifyArray.java:5: error: invalid method declaration; return type required public swapArrayEnds (10, 20, 30, 40) { Print - Your Confirmed Reservatic X b Answered: 4.2.3: Method definiti X ModifyArray.java:5: error: illegal start of type public swapArrayEnds (10, 20, 30, 40) { 3 errors ModifyArray.java:12: error: illegal start of expression public static void main (String [] args) { How was this section? Note: Although the reported line number is in the uneditable part of the code, the error actually exists in your code. Tools often don't recognize the problem until reaching a later line. Provide feedback zyBooks catalog Activity summary for assignment: Unit 4 Interactive Assignment Due: 10/31/2022, 3:59 PM -08 Feedback? ? Help/FAQ 70 % 70% submitted to Stacey Queen X : 9:11 AM 8/30/2022
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education