
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
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}. The array's size may differ from 4.
new code can only be added between existing code. as seen in image.
![INMAL ON HENGE
1 import java.util.Scanner;
2
3 public class ModifyArray {
4
5 /* Display array values */
6
7
8
9
10
11
12
13 }
14
15
16
public void displayValues (int [] arrayVals) {
int i;
17
for (i = 0; i< arrayVals. length; ++i) {
System.out.print (arrayVals[i] + ");
"1
}
System.out.println("");
ADD NEW JAVA CODE HERE***
*****
/
♥](https://content.bartleby.com/qna-images/question/0cc153ae-b205-4fb2-9991-7cf6a21d5016/f27e5052-1291-424e-a57b-53cd5e33698f/u6f0i5m_thumbnail.png)
Transcribed Image Text:INMAL ON HENGE
1 import java.util.Scanner;
2
3 public class ModifyArray {
4
5 /* Display array values */
6
7
8
9
10
11
12
13 }
14
15
16
public void displayValues (int [] arrayVals) {
int i;
17
for (i = 0; i< arrayVals. length; ++i) {
System.out.print (arrayVals[i] + ");
"1
}
System.out.println("");
ADD NEW JAVA CODE HERE***
*****
/
♥
![15
16
17
18
19
20
21
22
23
24
25
26
H O o 00 a u Р
~ ~ ~ ~ ~
****ADD NEW JAVA CODE HERE***
public static void main (String [] args) {
int numElem
4;
27
28
29
30
31 }
32 3
int[] sortedArray = new int [numElem];
ModifyArray numInverter = new ModifyArray ();
// Add values to the array
sortedArray[0] = 10;
sortedArray[1]
20;
sorted Array[2] = 30;
sorted Array[3] = 40;
numInverter.swapArrayEnds
(sortedArray);
numInverter.displayValues (sortedArray);
**** f](https://content.bartleby.com/qna-images/question/0cc153ae-b205-4fb2-9991-7cf6a21d5016/f27e5052-1291-424e-a57b-53cd5e33698f/f52ulam_thumbnail.png)
Transcribed Image Text:15
16
17
18
19
20
21
22
23
24
25
26
H O o 00 a u Р
~ ~ ~ ~ ~
****ADD NEW JAVA CODE HERE***
public static void main (String [] args) {
int numElem
4;
27
28
29
30
31 }
32 3
int[] sortedArray = new int [numElem];
ModifyArray numInverter = new ModifyArray ();
// Add values to the array
sortedArray[0] = 10;
sortedArray[1]
20;
sorted Array[2] = 30;
sorted Array[3] = 40;
numInverter.swapArrayEnds
(sortedArray);
numInverter.displayValues (sortedArray);
**** f
Expert Solution

arrow_forward
Step 1: Overview of the question
The method swapArrayEnds() swaps the first and last elements of its array parameter..
Step by stepSolved in 3 steps

Knowledge Booster
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
- Write the definition of a method reverse, whose parameter is an array of chars. The method reverses the elements of the array. The method does not return a value.arrow_forwardCreate a program that will encrypt letters and create a secret code. You will create an array of numbers from 0 - 25. use [i for i in range (26)] to create an array of numbers from 0 - 25. use random.shuffle to to shuffle the above array. This will be used for a new letter index order. For example: The first created array [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25] gets shuffled to become[2, 14, 12, 20, 16, 5, 11, 1, 13, 17, 15, 21, 19, 10, 23, 22, 25, 3, 6, 7, 18, 4, 9, 24, 0, 8] This will be used as the new index for the encrypted alphabet. create an array of letters using list(string.ascii_lowercase), this requires importing the string module. This will create: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] Accept an input of a word. Using the above tables take each letter of the word and convert it to the encrypted letter. Print each…arrow_forwardJava Complete the method with explaining, thank you!arrow_forward
- Four integers are read from input and stored into the array arrayToModify. Write a static method resetFirstValue() that takes an integer array parameter and replaces the first element with 1. Ex: If the input is 55 45 70 65, then the output is: Original array: 55 45 70 65 Changed array: 1 45 70 65 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 Scannerscnr=newScanner(System.in); finalintNUM_ELEM=4; int[] arrayToModify=newint[NUM_ELEM]; inti; intuserNum; for (i=0; i<arrayToModify.length; ++i) { arrayToModify[i] =scnr.nextInt(); } System.out.print("Original array: "); printArr(arrayToModify); resetFirstValue(arrayToModify); System.out.print("Changed array: "); printArr(arrayToModify); } }arrow_forwardplease read the directions carefullyarrow_forwardGiven the below 2 arrays: int arr1[] = { 9,8,7,6,5,4,3,2,1,0 }; int arr2[] = { 99, 89, 79, 69, 59 }; Write a program to replace 79 in arr2 with 4 from arr1. Print the final arr2 using Arrays.toString() method. Hint: Use System.arraycopy() methodNote: For all these programs, please submit the program’s .java file and screenshot of output.arrow_forward
- Define an empty array with 4 elements inside the "main" method. The value '-1' from the user to this arrayRecord the numbers entered by the user in order until they arrive. User array with 4 elementsAfter adding, write the required method so that it can continue adding elements. This method will take the array as a parameter, expand the size of the array and return the array variable.will return. Using this method you defined, the user can add elements to the array.make it continue.arrow_forwardImplement getArrayElmsInRange Method Details: getArrayElemsInRange public static int[] getArrayElemsInRange(int[] array, int lower, int upper) Returns an array with values in the range defined by lower (inclusive) and upper (inclusive). Feel free to use the getCountInRange method during the implementation of this method (See below). Parameters: array - integer array lower - lower limit upper - upper limit Returns: array with values in the range or empty array Throws: java.lang.IllegalArgumentException - if array is null or lower is greater than upper. Any error message is fine (e.g., "Invalid parameters(s)") getCountInRange Method: class Main { // this function will return the number elements in the given range public static int getCountInRange(int[] array, int lower, int upper) { int count = 0; // to count the numbers // this loop will count the numbers in the range for (int i…arrow_forwardWrite a void method selectionSortDescendTrace() that takes an integer array, and sorts the array into descending order. The method should use nested loops and output the array after each iteration of the outer loop, thus outputting the array N-1 times (where N is the size). Complete main() to read in a list of up to 10 positive integers (ending in -1) and then call the selectionSortDescendTrace() method. If the input is: 20 10 30 40 -1 then the output is: 40 10 30 20 40 30 10 20 40 30 20 10arrow_forward
- Write a method that takes a rectangular two-dimensional array of type int. The method returns true if the sum of the even elements of the parameter array are larger than the sum of the odd elements, otherwise the method returns false. public static boolean sum(int[]0 in) Taken array Result 1 -3 17 5 -2 30 true 1 3 -1 -1 -3 -4 7 -1 10 false -1 3 -4 15arrow_forwardWrite a static method that displays all combinations of picking two numbers from the array list: public static void combinations(ArrayList<Integer> list) Include the driver program that prompts the user to enter 10 integers and displays all combinations of picking two numbers from the array list.arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

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)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education