Data Structures and Algorithms in Java
6th Edition
ISBN: 9781118771334
Author: Michael T. Goodrich
Publisher: WILEY
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 3, Problem 2R
Write a Java method that repeatedly selects and removes a random entry from an array until the array holds no more entries.
Expert Solution & Answer
Learn your wayIncludes step-by-step video
schedule04:45
Students have asked these similar questions
Write a Java program named Findletter that asks the user to enter 10 letters and store them in an array. Then it should ask the user to enter a letter (char value) to search for it. Then, if the entered letter is found, the program should display the message "The letter is in the array", otherwise it should display the message "The letter is not in the array".
Java
Problem: Implementing a method to print a cell's neighbors on a 2D array. The method's header is provided. The main method (do not alter it)w ill read N numbers to create the 2D array and it will call the method for you. Do not go out of the bounds of the 2D array.
I have attached what it should look like with the following input:
4 4
1 2 3 4 7 8 9 10 13 14 15 16 19 20 21 22
2 2
Code I have so far:
import java.util.Arrays;import java.util.Scanner;public class Problem3 {public static void printNeighbours(int[][] data, int row, int col){}public static void main(String[] args) {Scanner kb = new Scanner(System.in);int[][] data = new int[kb.nextInt()][kb.nextInt()];for (int i = 0; i < data.length; i++) {for (int j = 0; j < data[0].length; j++) {data[i][j] = kb.nextInt();}}System.out.println("The 2D Array:");for (int[] cols : data) {System.out.println(Arrays.toString(cols));}int row = kb.nextInt();int col = kb.nextInt();System.out.printf("The centre point is: %d %d…
in java write a method that given an integer array, computes and returns the sum of all negative numbers in the array.
Example:
array: 13, -2, 3, -4, -5
result: x= -2 -4 -5;
x= -11
Chapter 3 Solutions
Data Structures and Algorithms in Java
Ch. 3 - Prob. 1RCh. 3 - Write a Java method that repeatedly selects and...Ch. 3 - Prob. 3RCh. 3 - The TicTacToe class of Code Fragments 3.9 and 3.10...Ch. 3 - Prob. 5RCh. 3 - Prob. 6RCh. 3 - Prob. 7RCh. 3 - Prob. 8RCh. 3 - Prob. 9RCh. 3 - Prob. 10R
Ch. 3 - Prob. 11RCh. 3 - Prob. 12RCh. 3 - Prob. 13RCh. 3 - Prob. 14RCh. 3 - Prob. 15RCh. 3 - Prob. 16RCh. 3 - Prob. 17CCh. 3 - Prob. 18CCh. 3 - Prob. 19CCh. 3 - Give examples of values for a and b in the...Ch. 3 - Suppose you are given an array, A, containing 100...Ch. 3 - Write a method, shuffle(A), that rearranges the...Ch. 3 - Suppose you are designing a multiplayer game that...Ch. 3 - Write a Java method that takes two...Ch. 3 - Prob. 25CCh. 3 - Prob. 26CCh. 3 - Prob. 27CCh. 3 - Prob. 28CCh. 3 - Prob. 29CCh. 3 - Prob. 30CCh. 3 - Prob. 31CCh. 3 - Prob. 32CCh. 3 - Prob. 33CCh. 3 - Prob. 34CCh. 3 - Prob. 35CCh. 3 - Write a Java program for a matrix class that can...Ch. 3 - Write a class that maintains the top ten scores...Ch. 3 - Prob. 38PCh. 3 - Write a program that can perform the Caesar cipher...Ch. 3 - Prob. 40PCh. 3 - Prob. 41PCh. 3 - Prob. 42PCh. 3 - Prob. 43P
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Mass and Weight Scientists measure an objects mass in kilograms and its weight in newtons. If you know the amou...
Starting Out With Visual Basic (7th Edition)
What are two differences between a set and a vector?
Starting Out with C++ from Control Structures to Objects (9th Edition)
Big data Big data describes datasets with huge volumes that are beyond the ability of typical database manageme...
Management Information Systems: Managing the Digital Firm (15th Edition)
This type of file contains data that has not been converted to text. a. text file b. binary file c. Unicode fil...
Starting Out with Python (3rd Edition)
a. What Boolean operation does the circuit compute? b. What Boolean operation does the circuit compute?
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Design nested decision structures that perform the following: If amount1 is greater than 10 and amount2 is less...
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
- Using dr java Write a Java program to do the following task: Create an integer array of size 10. Initialize it with 10 random numbers ranging from 50 to 160 (both included). Pass the array to a method that calculates the average of those 10 numbers. Print the average in the method.arrow_forwardFor Beginners Java: Write a program that ask the user to enter a list of positive scores until the user enters a negative score to terminate the input. You need to store these scores in an array. You can assume the maximum number of scores the user may enter is 50. However, you need to keep track of the actual number of scores entered. Write 2 methods: 1. calculateAverage(): this method takes the list of scores and return the average score. 2. countPerfectScores(): this method takes the list of scores and return the number of perfect scores (100). The main program reads the input and calls these methods and print the results. Please make sure you write a comment line to document what your method does.arrow_forwardPseudocode for Java code Write the algorithm in pseudocode for a method that accepts three parameters: an integer array, an integer representing the number of valid values in the array, and an integer representing a factor. The method will count the number of valid values in the array that are multiples of the factor and will return the count. There is a Java operator that might be very helpful in solving this problem. Testing Above problem: Assuming that the first two parameters are an array containing 4, 10, 15, 12, 8, 20, 100, 25, 32, 7, 28, and 48 and the number 12, come up with three good test cases for the factor and the return value. factor numMultiplesarrow_forward
- Write a java program to create prices of Shopping Cart items that provides a menu: 1: Create a new price for each item in the Cart list 2: Print the price of a particular item 0: Exit Enter your choice: Define an array: ShoppingCart which stores prices of items. Define another array: ItemsNames of the same size that stores names of such items. Assume that there are 10 items. When the user presses 1, the program call a method that creates a new price for each item in the array using random numbers between 1 and 1000 AED [not inclusive]. If the user presses 2, the program call a method that prints the name of the requested item and its price. Use switch case statement for choosing among the menu options. Make a method to display the menu to give the user the possibility to use the menu as much as he/she wants.arrow_forwardWrite a java program to create prices of Shopping Cart items that provides a menu: 1: Create a new price for each item in the Cart list 2: Print the price of a particular item 0: Exit Enter your choice: Define an array: ShoppingCart which stores prices of items. Define another array: ItemsNames of the same size that stores names of such items. Assume that there are 10 items. When the user presses 1, the program call a method that creates a new price for each item in the array using random numbersbetween 1 and 1000 AED [not inclusive]. If the user presses 2, the program call a method that prints the name of the requested item and its price. Use switch case statement for choosing among the menu options. Make a method to display the menu to give the user the possibility to use the menu as much as he/she wants.arrow_forwardWrite java code that recursively calculates the Sum of the array cells. Program requirements: Create an array named MyArr and initialize it as follow: 243 88 31 19 27 81 100 6 10 5 1- Write a method named ArrSum that recursively calculates the Sum of the numbers in the Array and returns the Sum of the numbers. Hint: Method with 1 parameter (the Array) that returns 1 value (the Array's Sum). 2- Write a method named Display that displays the Array contents and Sum of the numbers. Hint: Method with 2 parameters (the Array) and Sum with no returns (void) 3- Write a method named ArrSort using the bubble sort to sort Array. 4- Your program output format must be the same as the following: =>> Array Summation Array: 5 6 10 19 27 31 81 88 100 243 Sum: 610 =>> End of the Program Be sure to add Documentation / Commentsarrow_forward
- Write a Java method that reverses a given array. the method that reverses the array passed in the argument and returns this array. Write a test program that prompts the user to enter ten numbers, invokes the method to reverse the numbers, and displays the numbers.arrow_forwardWrite a Java program that takes an integer array parameter and returns the sum of integers contained within the array.arrow_forwardIn Java: Write a method that multiplies all elements in the array by 3 and returns it to the main method.arrow_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