Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
11th Edition
ISBN: 9780134671710
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 19.9, Problem 19.9.4CP
What would be wrong if the printResult method is defined as follows?
public static void printResult(
E[][] sm1, E[][] m2, E[][] m3, char op)
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
public static void main(String[] args) {
int[] funky = {1, -5, 3, -5, 6, 6, 6, 7, -5};int expectedFunkyRange = 5; // |6 - 1| = 5System.out.println("Expected funkyRange of " + Arrays.toString(funky) + " to be " + expectedFunkyRange + " and got " + funkyRange(funky));int[] funkyTwo = {6, 6, 4, 4, 4, 2, 2, 8, 4, 1, 1};int expectedFunkyRangeTwo = 4; // |4 - 8| = 4System.out.println("Expected funkyRange of " + Arrays.toString(funkyTwo) + " to be " + expectedFunkyRangeTwo + " and got " + funkyRange(funkyTwo));
Write a static method: public static int WeirdRange(int[] a) that that calculates the difference between the mode and "anti-mode" of an array of integers. This difference should be a positive number (you can use Math.abs to calculate an absolute value). If the array is empty or null, return -1. If the array has only one thing in it, return 0 (since the mode and anti-mode are the same).
Definitions:
The mode of an array is the element that occurs the most frequently.…
use java
// MichiganCities.java - This program prints a message for invalid cities in Michigan.
// Input: Interactive.
// Output: Error message or nothing.
import java.util.Scanner;
public class MichiganCities
{
public static void main(String args[]) throws Exception
{
// Declare variables.
String inCity; // name of city to look up in array.
// Initialized array of cities in Michigan.
String citiesInMichigan[] = {"Acme", "Albion", "Detroit", "Watervliet", "Coloma", "Saginaw", "Richland", "Glenn", "Midland", "Brooklyn"};
boolean foundIt = false; // Flag variable.
int x; // Loop control variable.
// Get user input.
Scanner input = new Scanner(System.in);
System.out.println("Enter the name of the city: ");
inCity = input.nextLine();
// Write your loop here.
for (x=0;x<= citiesInMichigan.length;x++){
if(citiesInMichigan[x]==inCity){
foundIt = true;…
Chapter 19 Solutions
Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
Ch. 19.2 - Are there any compile errors in (a) and (b)?Ch. 19.2 - Prob. 19.2.2CPCh. 19.2 - Prob. 19.2.3CPCh. 19.3 - Prob. 19.3.1CPCh. 19.3 - Prob. 19.3.2CPCh. 19.3 - Prob. 19.3.3CPCh. 19.3 - Prob. 19.3.4CPCh. 19.4 - Prob. 19.4.1CPCh. 19.4 - Prob. 19.4.2CPCh. 19.5 - Prob. 19.5.1CP
Ch. 19.5 - Prob. 19.5.2CPCh. 19.6 - What is a raw type? Why is a raw type unsafe? Why...Ch. 19.6 - Prob. 19.6.2CPCh. 19.7 - Prob. 19.7.1CPCh. 19.7 - Prob. 19.7.2CPCh. 19.7 - Prob. 19.7.3CPCh. 19.7 - Prob. 19.7.4CPCh. 19.8 - Prob. 19.8.1CPCh. 19.8 - Prob. 19.8.2CPCh. 19.8 - Prob. 19.8.3CPCh. 19.8 - Prob. 19.8.4CPCh. 19.8 - Prob. 19.8.5CPCh. 19.9 - Prob. 19.9.1CPCh. 19.9 - How are the add, multiple, and zero methods...Ch. 19.9 - How are the add, multiple, and zero methods...Ch. 19.9 - What would be wrong if the printResult method is...Ch. 19 - (Revising Listing 19.1) Revise the GenericStack...Ch. 19 - Prob. 19.2PECh. 19 - (Distinct elements in ArrayList) Write the...Ch. 19 - Prob. 19.4PECh. 19 - (Maximum element in an array) Implement the...Ch. 19 - (Maximum element in a two-dimensional array) Write...Ch. 19 - Prob. 19.7PECh. 19 - (Shuffle ArrayList) Write the following method...Ch. 19 - (Sort ArrayList) Write the following method that...Ch. 19 - (Largest element in an ArrayList) Write the...Ch. 19 - Prob. 19.11PE
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
State whether each of the following is true or false. If false, explain why. The break statement is required in...
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
This optional Google account security feature sends you a message with a code that you must enter, in addition ...
SURVEY OF OPERATING SYSTEMS
Write a recursive method that will remove all the vowels from a given string and return what is left as a new s...
Java: An Introduction to Problem Solving and Programming (8th Edition)
What is an object? What is a control?
Starting Out With Visual Basic (8th Edition)
How does pressure gas welding differ from the oxyfuel-gas process?
Degarmo's Materials And Processes In Manufacturing
ICA 8-19
Determine the mass in units of grams [g] of 0.35 moles [mol] of a new fictitious compound you have dev...
Thinking Like an Engineer: An Active Learning Approach (4th 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
- java program : Assume the following method is added to the ArrayStack class. What does this method do? public ArrayStack<E> Undefined() { int j = topOfStack; ArrayStack<E> st1= new ArrayStack<E>(topOfStack + 1); for(int i = 0; i < topOfStack + 1; i++) { st1.theData[j] = theData[i]; j-- ; } return st1; } The method will return a stack containing all the elements of “this” stack in the reverse order. The method will return a stack containing the alternative elements of “this” stack in the original order. The method will return a stack containing all the elements of “this” stack in the original order. The method will return a stack containing the alternative elements of “this” stack in the reverse order.arrow_forwardjava program : Assume the following method is added to the ArrayStack class. What does this method do? public ArrayStack<E> Undefined() { int j = topOfStack; ArrayStack<E> st1= new ArrayStack<E>(topOfStack + 1); for(int i = 0; i < topOfStack + 1; i++) { st1.theData[j] = theData[i]; j-- ; } return st1; } The method will return a stack containing all the elements of “this” stack in the reverse order. The method will return a stack containing the alternative elements of “this” stack in the original order. The method will return a stack containing all the elements of “this” stack in the original order. The method will return a stack containing the alternative elements of “this” stack in the reverse order.arrow_forwardMethod 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_forward
- 1. Write a program that calls a method that takes a character array as a parameter (you can initialize an array in the main method) and returns the number of vowels in the array. Partial program is given below. public class CountVowels{ public static void main(String[] args){ char[] arr= System.out.print("There are "+vowels(arr)+" vowels in the array");arrow_forwardpublic class ReplaceEvenWithZero { public static void main(String[] args) { int[]a = new int[]{14, 2, 19, 3, 15, 22, 18, 7, 44, 39, 51, 78} ; // Print array a for (int i = 0; i < a.length; i++) { System.out.print(a[i] + " "); } System.out.println(); // Replace the even elements. replaceEven(a); // Print array a again to see new elements. for (int i = 0; i < a.length; i++) { System.out.print(a[i] + " "); } System.out.println(); } /** Replace the even elements in the given array with 0 @param arr the array to use for the replacements */ public static void replaceEven(int[] arr) { //-----------Start below here. To do: approximate lines of code = 2 // Write a for loop to go through each element, determine if it is even //If so, replace with 0. Hint: use the modulus operator % to determine if an…arrow_forwardusing JAVAarrow_forward
- in javaarrow_forwardMethods Details: public static java.lang.StringBuffer[] getArrayStringsLongerThan(java.lang.StringBuffer[] array, int length) Returns a StringBuffer array with COPIES of StringBuffer objects in the array parameter that have a length greater than the length parameter. If no strings are found an empty array will be returned. Parameters: array - length - Returns: Throws:java.lang.IllegalArgumentException - When a null array parameter is providedarrow_forwardSubject: Java Programmingarrow_forward
- 1. For each statement, circle the response that best completes it. For the first nine statements, consider this Java method and the array shown to its right. array public static int linkSum(int'a, int startLoc, int sunlimit) ( startLoc; int sun 0, 1 while (1>0 & sun sunlimit) { aun- sum + a[i]; 1 = a[i]; } return dum; (i) The expression linkSum (junk, 3, 12) evaluates to a. 13 b. 22 c. 10 d. 1 (ii) The call linkSum (junk, b. 4 a. 1 c. 5 (iii) The call linkSum (junk, Array IndexOutOfBoundsException a. 1 c. 5 0 1 2 3 4 5 6 7 Junk 1 0141711131-1101 211 startLoc d. 6 ,20) results in an infinite loop. e. none of above ,15) results in an being thrown. d. 6 e. none of above b. 2 (iv) In the method above (applied to any array), we can be sure that at the moment that the loop terminates. a. a[i] startLoc || sun >= sunlimit d. 1 = sumlinit c. 1 <0 & sum e. none of the above (v) In the method above, each of int and static is a(n) a reserved word b. variable c. expression (vi) In the method…arrow_forward6arrow_forwardJava class Write a method named minimumValue, which returns the smallest value in an array that is passed (in) as an argument. The method must use Recursion to find the smallest value. Demonstrate the method in a full program, which does not have to be too long regarding the entire code (i.e. program). Write (paste) the Java code in this word file (.docx) that is provided. (You can use additional pages if needed, and make sure your name is on every page in this word doc.) Use the following array to test the method: int[] seriesArray = {-5, -10, +1999, +99, +100, +3, 0, +9, +300, -200, +1, -300} Make sure that the seriesArray only tests for values, which are positive, given your recursive 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
Introduction to Big O Notation and Time Complexity (Data Structures & Algorithms #7); Author: CS Dojo;https://www.youtube.com/watch?v=D6xkbGLQesk;License: Standard YouTube License, CC-BY