Java: An Introduction to Problem Solving and Programming (7th Edition)
7th Edition
ISBN: 9780133766264
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 7, Problem 10E
Write a static method remove {int v, int [] in} that will return a new array of the integers in the given array, but with the value v removed. For example, if v is 3 and n contains 0, 1, 3, 2, 3, 0, 3, and 1, the method will return an array containing 0, 1, 2, 0, and 1.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write the method sum2D() which accepts a two dimensional integer array and returns the sum of all the elements of the array.
Complete the method endsInFive that takes as arguments a 2D-array of integers and an integer value that represents a column index in the array. endsInFive returns the number of values in the column that end in 5. It is possible that the array is ragged, meaning that the number of columns in each row is different.
For example, 2 is returned if the following 2D-array is passed as the first argument of endsInFive and the integer 3 as the second argument (the values 25 and 115 end in five at column index 3).
3.
write a method called insert that inserts an element into an integer array. It should take 3
parameters: an int array, the number to be inserted and the index it should be inserted at. It
should return a new array that has the element inserted at the index (the new array should have
a length 1 longer than the original array).
Sample code
int[] a = {1,2,3,4,5};
int[] inserted = insert (a,9,0);
printArray (inserted);
int [] a = {1,2,3,4,5};
int[] inserted = insert (a,9,3);
printArray(inserted);
int [] a = {1,2,3,4,5};
int[] inserted = insert(a,9,5);
| printArray(inserted);
Sample output
912345
123945
123459
Chapter 7 Solutions
Java: An Introduction to Problem Solving and Programming (7th Edition)
Ch. 7.1 - What output will be produced by the following...Ch. 7.1 - What output will be produced by the following...Ch. 7.1 - What output will be produced by the following...Ch. 7.1 - Consider the following array: int [] a = new...Ch. 7.1 - What is wrong with the following code to...Ch. 7.1 - Write a complete Java program that reads 20 values...Ch. 7.2 - Write some Java code that will declare an array...Ch. 7.2 - Rewrite the method displayResults of the program...Ch. 7.2 - What output will be produced by the following...Ch. 7.2 - Give the definition of a static method called...
Ch. 7.2 - Give the definition of a static method called...Ch. 7.2 - Prob. 12STQCh. 7.2 - The following method compiles and executes but...Ch. 7.2 - Suppose that we add the following method to the...Ch. 7.3 - Prob. 15STQCh. 7.3 - Replace the last loop in Listing 7.8 with a loop...Ch. 7.3 - Suppose a is an array of values of type double....Ch. 7.3 - Suppose a is an array of values of type double...Ch. 7.3 - Prob. 19STQCh. 7.3 - Consider the partially filled array a from...Ch. 7.3 - Repeat the previous question, but this time assume...Ch. 7.3 - Write an accessor method getEntryArray for the...Ch. 7.4 - Prob. 23STQCh. 7.4 - Write the invocation of the method selectionSort...Ch. 7.4 - How would you need to change the method...Ch. 7.4 - How would you need to change the method...Ch. 7.4 - Consider an array b of int values in which a value...Ch. 7.5 - What output is produced by the following code?...Ch. 7.5 - Revise the method showTable in Listing 7.13 so...Ch. 7.5 - Write code that will fill the following array a...Ch. 7.5 - Write a void method called display such that the...Ch. 7.6 - Prob. 33STQCh. 7 - Write a program in a class NumberAboveAverage that...Ch. 7 - Write a program in a class CountFamiles that...Ch. 7 - Write a program in a class CountPoor that counts...Ch. 7 - Write a program in a class FlowerCounter that...Ch. 7 - Write a program in a class characterFrequency that...Ch. 7 - Create a class Ledger that will record the sales...Ch. 7 - Define the following methods for the class Ledger,...Ch. 7 - Write a static method isStrictlyIncreasing (double...Ch. 7 - Write a static method removeDuplicates(Character[]...Ch. 7 - Write a static method remove {int v, int [] in}...Ch. 7 - Suppose that we are selling boxes of candy for a...Ch. 7 - Create a class polynomial that is used to evaluate...Ch. 7 - Write a method beyond LastEntry (position) for the...Ch. 7 - Revise the class OneWayNoRepeatsList, as given in...Ch. 7 - Write a static method for selection sort that will...Ch. 7 - Overload the method selectionSort in Listing 7.10...Ch. 7 - Revise the method selectionSort that appears in...Ch. 7 - Prob. 18ECh. 7 - Write a sequential search of an array of integers,...Ch. 7 - Write a static method findFigure (picture,...Ch. 7 - Write a static method blur (double [] [] picture)...Ch. 7 - Write a program that reads integers, one per line,...Ch. 7 - The following code creates a small phone book. An...Ch. 7 - Write the method rotateRight that takes an array...Ch. 7 - The following code creates a ragged 2D array. The...Ch. 7 - Write a program that will read a line of text that...Ch. 7 - Prob. 2PPCh. 7 - Add a method bubbleSort to the class ArraySorter,...Ch. 7 - Add a method insertionSort to the class...Ch. 7 - The class TimeBook in Listing 7.14 is not really...Ch. 7 - Define a class called TicTacToe. An object of type...Ch. 7 - Repeat Programming Project 10 from Chapter 5 but...Ch. 7 - Prob. 8PPCh. 7 - Write a GUI application that displays a picture of...Ch. 7 - ELIZA was a program written in 1966 that parodied...Ch. 7 - Prob. 11PPCh. 7 - Create a GUI application that draws the following...Ch. 7 - Practice Program 2 used two arrays to implement a...Ch. 7 - Practice Program 5.4 asked you to define Trivia...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Contrast the following terms: chief data officer; DBA data administration: database administration open source ...
Modern Database Management
Design a class named Pet, which should have the following fields: name. The name field holds the name of a pet....
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
(You should do the previous two Practice Programs before doing this one.) Write a program that combines the fun...
Problem Solving with C++ (10th Edition)
Write a loop equivalent to the for loop above without using .
C Programming Language
Combine the statements that you wrote in Exercise 4.5 into a Java application that calculates and prints the su...
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Rewrite the following If-Then-Else If statement as a Select Case statement. If selection == 1 Then Display "You...
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
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
- 3. write a method called insert that inserts an element into an integer array. It should take 3 parameters: an int array, the number to be inserted and the index it should be inserted at. It should return a new array that has the element inserted at the index (the new array should have a length 1 longer than the original array). Sample code int [] a = {1,2,3,4, 5}; int[] inserted = insert (a,9,0); printArray (inserted); int[] a = int[] inserted = insert(a,9,3); printArray (inserted); int[] a = {1,2,3,4,5}; int [] inserted = insert (a,9,5); printArray(inserted); Sample output 9123 4 5 {1,2,3,4,5}; 123945 1234 59arrow_forwardWrite a method with header static void DisplayIntArray(int[] numbers). The first argument is an array of ints. There is no return value. This method displays all the elements of the argument on a single line. Each item will occupy three columns.Call this method from main with a suitable argument. Write a method with header static int[] GenerateRandomIntArray(int numberOfItems, int largestValue). The first argument is an int indicating the number of elements that will be present in the return array. The second argument is an int representing the largest item in the array. The returned value is an array of integers. This method does the following: Declare and initialized a variable of type Random (Random generator = new Random();) Declare an array of type int (you may call it result) Allocate storage for the correct number of items Using your favorite looping statement, assign a random integer to each element of the array (result[i] = generator.Next(largestValue);) In your…arrow_forwardA bit new to methods and need a little bit of help. Swap Method Your task is to write a public static method named swap that takes a single parameter which is an array of doubles. This method should swap the first and last element in the array and then return the adjusted double array. You can assume that all arrays passed into the method are a length of 2 or more. For example, the test data provided when passed into the swap method should go from: {8.34, 7.221, 10.643, 93.2} toarrow_forward
- Method Details: public static java.lang.String getArrayString(int[] array, char separator) Return a string where each array entry (except the last one) is followed by the specified separator. An empty string will be return if the array has no elements. Parameters: array - separator - Returns: stringThrows:java.lang.IllegalArgumentException - When a null array parameter is providedarrow_forwardWrite a method that returns a new array by eliminating theduplicate values in the array using the following method header:public static int[] eliminateDuplicates(int[] list)Write a test program that reads in 10 integers, invokes the method, and displaysthe distinct numbers separated by exactly one space. Here is a sample run of theprogram: Enter 10 numbers: 1 2 3 2 1 6 3 4 5 2 ↵EnterThe distinct numbers are: 1 2 3 6 4 5arrow_forward5. Write a static method largestColumnFirst() that receives as parameter a 2D array numAr,finds the column with the largest sum, and switches it with the first column. For example:6 7 9 4 8 9 7 6 4 83 2 7 4 1 → 7 2 3 4 19 4 5 8 3 5 4 9 8 3arrow_forward
- The rotateLeft method takes an array of integers, and an integer number of places, and returns a new copy of the array that contains a "rotated" version of the input array. Rotation means that elements have been shifted leftwards by that number of places, moving elements off one end of the array and onto the other end. For example, [11, 12, 13, 14, 15] rotated left by 2 places results in [13, 14, 15, 11, 12].arrow_forward. - Write a method called checkArrays that accepts as parameters two arrays of integer (A and B of the same size) and returns another array of integers (C) initialized as follows: C[i] = 1 if B[i] divides A[i], otherwise C[i]=0. For example: A 12 20 4 30 3 6 24 C 1 0 0 1 B Use the following method header: public static int[] checkArrays (int[] A, int[ 1 B) Sample Run: 15 Write a void method called printArray that accepts as parameters an array of integers and print its values. Use the following method header: public static void printArray (int[] arr) ArrayA: 12 ArrayB: 3: ArrayC: 1 17 260 9 Write a main method to test the above methods as follows: Declare and initialize 2 integer arrays (arrayA and arrayB) of size 5 (fill the 2 arrays with random integers between 1 and 100). Invoke the method printArray to display the values stored in the two arrays. Invoke the method checkArrays and pass to it the two arrays arrayA and arrayB. Invoke the method printArray to display the values of the…arrow_forwardImplement getEvens method Method Details getEvens public static int getEvens(int[] array, int[] result) Initializes the out parameter result with even values found in array Parameters: array - integer array result - integer array Returns: Number of even values found Throws: java.lang.IllegalArgumentException - if array or result (or both) are null, or if result's length is less than array's length. Any error message is fine (e.g., "Invalid parameters(s)")arrow_forward
- Design and implement a method to double all elements of an array. Important: You don’t need to test test method in main(). You don’t need to initialize the array. pubilc static void doubleElements(int [] arr) { // your code goes here }arrow_forwardWrite a method that sums the areas of all thegeometric objects in an array. The method signature is:public static double sumArea(GeometricObject[] a)Write a test program that creates an array of four objects (two circles and tworectangles) and computes their total area using the sumArea method.arrow_forwardWrite 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_forward
arrow_back_ios
SEE MORE QUESTIONS
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
Definition of Array; Author: Neso Academy;https://www.youtube.com/watch?v=55l-aZ7_F24;License: Standard Youtube License