Java: Introduction to Problem Solving and Programming
7th Edition
ISBN: 9780133834604
Author: 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
FOR JAVA
Write a method that takes a one dimensional integer array, an integer (as index) and another integer (as number). Your program must insert the number into the given index, shift the rest of the elements to the right, and return the new array. For instance, if we want to insert the number 0 into position 3 of {1, 2, 3, 4, 5}, your method must return {1, 2, 3, 0, 4, 5}.
Write the method printTail() method that accepts an array of integers and an integer index as parameters and prints all the array elements starting from the index passed. For example if printTail(x,5) is invoked, it should print all the elements of the array x starting at x[5].
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}.
import java.util.Scanner;
public class ModifyArray {
/* Your solution goes here */
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("");}}
Chapter 7 Solutions
Java: Introduction to Problem Solving and Programming
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
- 5. 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_forwardWrite the Java method averageOfDoubles that is passed an array of double values, and returns the average of the array values.You can assume the array length is a positive integer.arrow_forwardFOR JAVA Write a method that takes an integer array and returns the difference between the sum of even indexed elements and the sum of odd indexed elements in that array.arrow_forward
- java Write a method that takes rows and columns as a parameter, and returns a 2D array of the designated size, filled with empty Strings. I currently have public static String[][] createArray(int row, int col) { String[][]arr=new String[row][col]; return arr; } but it returns the 2d array filled with null?arrow_forwardWrite a static method: public static double intersectionSum(double[] a, double[] b) that takes two double arrays as arguments and returns the sum of the elements the two arrays have in common. In other words, the result should be the sum of every element in the two arrays where a[i] is equal to b[i] for some index i. Note that the two arrays may not be the same length. In these cases, you should only consider the indices that the arrays have in common (the indices of the shorter array). If either (or both) arrays are empty or null, the result should be 0.0. Example 1: intersectionSum({3.0, -4.0, 5.8, 6.75}, {3.0, 2.5, 5.8, 4.95}) è 8.8, since a[0] == b[0] and a[2] == b[2] and 3.0 + 5.8 = 8.8 Example 2: intersectionSum({8.5, 9.75, 1.25}, {3.5, 9.75, 1.25, 8.5, -2.34}) è11.0, since a[1] == b[1] and a[2] == b[2] and 9.75 + 1.25 = 11.0arrow_forwardWrite the method sum2D() which accepts a two dimensional integer array and returns the sum of all the elements of the array.arrow_forward
- write a java program: (must use set or map) Given an integer array and a value k, write a method called kDifference() thatfinds a pair in the array such that their difference equals k. If such a pair existsonly print the first one you find, otherwise state that there is no pair.arrow_forwardWrite a helper method, with the signature eliminateZerosinArray[int[]): int[], that takes a single dimensional int array as an argument, and returns a new array that only contains the original values that are not equal to 0. The returned array may be the same size or smaller depending on whether there are values that are equal to 0 in the original array. You may only use standard intl| arrays to solve this.arrow_forwardThe 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 that takes two arrays of integers and combines the two arrays into one array with only unique integers. In other words, combine two arrays but don't include repeats of any numbers. For example, if you have {1, 2, 3, 4, 5} and {3, 4, 5, 6, 7}, when you combine these, the result should be {1, 2, 3, 4, 5, 6, 7}. (Note that you don't have to put them in order, but that might help you when writing your algorithm) (in java)arrow_forwardWrite a method that takes two arrays of integers and combines the two arrays into one array with only unique integers. In other words, combine two arrays but don't include repeats of any numbers. For example, if you have {1, 2, 3, 4, 5} and {3, 4, 5, 6, 7}, when you combine these, the result should be {1, 2, 3, 4, 5, 6, 7}. (Note that you don't have to put them in order, but that might help you when writing your algorithm)arrow_forwardJAVA complete a method that swaps the first and second half of an array of integers. For example, if the array contains the values 1 4 9 16 25 36then after calling the method, it should contain the values16 25 36 1 4 9If the array contains an odd number of elements, leave the middle element in place. For example, 1 4 9 16 25 36 45becomes25 36 45 16 1 4 9arrow_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