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 21C
Suppose you are given an array, A, containing 100 integers that were generated using the method r.nextInt(10), where r is an object of type java.util.Random. Let x denote the product of the integers in A. There is a single number that x will equal with probability at least 0.99. What is that number and what is a formula describing the probability that x is equal to that number?
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
I need help with creating a Java program described below:
Minesweeper.Write a program that reads three numbers, m, n, and p and produces an m-by-n Booleanarray where each element is occupied with probability p. In the minesweeper game, occupiedcells represent bombs and empty cells represent safe cells.Print out the array using an asterisk for bombs and a period for safe cells.Then, create an integer two-dimensional array with the number of neighboring bombs (above,below, left, right, or diagonal).
* * . . . * * 1 0 0. . . . . 3 3 2 0 0
. * . . . 1 * 1 0 0Write your code so that you have as few special cases as possible to deal with, by using an(m+2)-by-(n+2) Boolean array.
Consider an array of length n containing unique integers in random order and in the range 1 to
n + 1. For example, an array of length 5 would contain 5 unique integers selected randomly from
the integers 1 through 6. Thus, the array might contain 3 6 5 1 4. Of the integers 1 through 6,
notice that the 2 was not chosen and is not in the array.
Write Java code that finds the integer that does not appear in such an array. Your solution should
use
a.
O(n²) operations
in java Declare and initialize an array with 8 integer elements. Use therandom method of the Math class to initialize the values with randomintegers between 1 and 50 (exclude 50) and print each of them onConsole.
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
Porter’s competitive forces model: The model is used to provide a general view about the firms, the competitors...
Management Information Systems: Managing the Digital Firm (15th Edition)
T F: Radio buttons that are placed inside a group box are treated as one group, separate and distinct from any ...
Starting Out With Visual Basic (8th Edition)
Categorize each of the following items as either hardware or software: CPU C++ compiler ALU C++ preprocessor in...
C How to Program (8th Edition)
What is the difference between a protected class member and a private class member?
Starting Out with Java: Early Objects (6th Edition)
What is the output produced by the following?
Absolute Java (6th Edition)
At what time(s) can an object diagram change? How is it changed?
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
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 a program using java Write the class Student having attributes Id (int), name (String), age (int) and cgpa (double) and methods to set the values of attributes and to return them.Write another class name Student Management having array of students and count of students as attribute. There should be method for the following:1. Add new Student in Array2. Remove a Student from Array using Id (of Student)3. Sort the Students in array using Id (ascending order)4. Sort the Students in array using Age (ascending order)5. Sort the Students in array using CGPA (ascending order)6. Reverse the order of the Students in array7. Display information of all Students in array (from zero index to last index)Write another class named as Main having main method and show activity of above methods.1. Add 5 Students in array2. Display all students in array3. Remove a student by name [Hint: Use equals method to check equality e.g. str1.equals(str2) ]4. Display all student in array5. Sort array by Id and…arrow_forwardWrite a Java method that takes an array of type int and returns a boolean value. The method returns true if the number of positive elements in the parameter array is larger than the number of negative elements. The method returns false if any of the following conditions is satisfied: • The parameter array is of length of 0 or 1 • The number of positive elements of the parameter array is less than or equal to the number of negative elements • The number of positive elements or negative elements is equal to zero The method's header is as follows. public static boolean verify (int[] x) Sample run Result int[] x = (1, 2, 3}; verify(x); {5}; verify(x); int[] x = {1, 2, 3, -5, -1}; boolean b = verify(x); int[] x = new int[0]; verify(x); false boolean b = int[] x = boolean b = false true false boolean b = BIU A Paragraph +varrow_forwardwrite a java method with followin instraction : Write a method called prioritizeQueue to give priority for vaccination for elderly persons. The method is to be in a class called VaccinationQueue and has two parameters q1 and q2 type ArrayQueue. The q1 and q2 data are of type Integer. Assume that initially q1 is not empty and q2 is empty. The method will insert from q1 those elements towards the beginning of the queue (front) q2 whose data is greater than or equal to 45 and will insert those elements whose data is less than 45 and greater than or equal to 18 towards the end (rear) of q2. Any data item less than 18 of q1 will not be inserted in q2. It returns the number of elements added to q2. Class ArrayQueue and all its methods including iterator are available for use. You can also create temporary queues. You are not allowed to use arrays or any other data structure. Example: Before method call: front rear q1: 14 25 50…arrow_forward
- Implement the vacuum cleaning agent function in Python/Java for the scenario described below: Consider two-dimensional Boolean array of size m x n (m and n can each be equal to 4) where m is the number of rows, and n is the number of columns. Obtain numerical positive integer values for m and n as inputs from the user. Generate random numbers and scale them down to either a “0” or a “1” according to whether they represent “Clean” or “Dirty”, respectively. After filling the array with 0s or 1s, start at some random array position indicating the initial position of the vacuum cleaner. First check if at that current position, there is the presence of a “Dirt” or not determined by whether 0 or 1 is filled in at that initial position of the vacuum cleaner. If there is a “Dirt”, clean it, and if there is no “Dirt” do a No-operation. After this is done, generate random numbers modulo 4 to obtain random numbers 0, 1, 2, 3 indicating whether to take a left, right, up or down correspondingly. If…arrow_forwardWrite a JAVA program that handles a 2-dimensional array representing a 3x3 tic-tac-toe board. In the game, players take turns writing an X or an O and trying to get three in a row. Write three methods, one to solve for a horizontal win, one to solve for a vertical win, and one to solve for a diagonal win. A win occurs when three symbols for a player are in a line (horizontal, vertical, or diagonal). Create four 2-d (3x3) arrays, one with a horizontal win for O, one with a vertical win for X, one with a diagonal win for O, and the last being a cat game (no player wins). It is tempting to populate the arrays with a ‘X’ and ‘O’ characters but consider representing these values with int values instead which makes calculating a win much easier. Consider a zero value as an empty cell. You do not have to write code to input the values, just define the four arrays using initializer lists (see example below). For example: an array with { {1, 0, -1}, {1, -1, 0}, {1, -1, 0} } has a vertical…arrow_forwardWrite a Java method that takes an array of type int and returns a boolean value. The method returns true if the number of positive elements in the parameter array is larger than the number of negative elements. The method returns false if any of the following conditions is satisfied: • The parameter array is of length of O or 1 • The number of positive elements of the parameter array is less than or equal to the number of negative elements • The number of positive elements or negative elements is equal to zero The method's header is as follows. public static boolean verify (int[] x) Sample run int[] x = boolean b = Result {1, 2, 3}; false verify(x); int[] x = (5}; boolean b = false verify(x); int[] x = {1, 2, 3, -5, -1}; verify(x); int[] x = new int[@]; verify(x); true boolean b% = false boolean b% = +v Paragrapharrow_forward
- FOR JAVA Write a method that takes an integer array, prints the elements that are divisible by 3 and returns the sum of these elements. 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. Write a method that takes a String array and an integer as parameters and prints the Strings in the array whose length is greater than the second parameter. Write a method that takes two integer arrays, and returns a new array by taking the intersection of the two arrays.arrow_forwardwrite java program for the above questionarrow_forwardWrite a program in java in which we had an array and you have to find Whether this array is monotonic or notarrow_forward
- Write a Java program (Hangman.java) to play the classic word game Hangman. In the game, a word is randomly selected from an array of possible words. Then, the user is prompted to guess letters in the word one at a time. When the user makes a correct guess, all instances of that letter in the word are shown. When all letters in the word have been guessed, the game ends and the score (number of missed guesses) is displayed. A user can play the game multiple times if they choose. Here is a sample run of a correct program (user input indicated by orange text):Enter a letter in word ******** > cEnter a letter in word c******* > rEnter a letter in word c******r > s s is not in the wordEnter a letter in word c******r > tEnter a letter in word c****t*r > mEnter a letter in word c*m**t*r > t t is already in the wordEnter a letter in word c*m**t*r > pEnter a letter in word c*mp*t*r > oEnter a letter in word comp*t*r > eEnter a letter in word comp*ter >…arrow_forwardProgramming exercise (in java eclipse, please add comments for each step). Write a complete Java program named FindProduct that contains the following: a. A main method asks the user to provide the number of rows and columns for a 2-dimensional array of integers. b. A main method calls the getArray() method that creates the 2D array of specified size and populates it with random values from 0 to 100. c. A main method prints the elements of the 2D array created by getArray(). d. A main method calls the printProduct method that will: i. Receive the two-dimensional array as input ii. Calculate the product of elements in each row of the array iii. Display the product on the Console. The product of all elements in each row should be formatted as "Row 1 Product XXXX"arrow_forwardWrite a JAVA program to create an array of objects of a class student. The class should have field members id, total marks and marks in 3 subjects viz. Physics, Chemistry & Maths. Accept information(get input from user) of 3 students and display them in tabular form in descending order of the total marks obtained by the student.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