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 1, Problem 17C
Write a short Java method that takes an array of int values and determines if there is a pair of distinct elements of the array whose product is even.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write 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
+v
Write 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
Paragraph
FOR 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.
Chapter 1 Solutions
Data Structures and Algorithms in Java
Ch. 1 - Prob. 1RCh. 1 - Suppose that we create an array A of GameEntry...Ch. 1 - Write a short Java method, isMultiple, that takes...Ch. 1 - Write a short Java method, isEven, that takes an...Ch. 1 - Write a short Java method that takes an integer n...Ch. 1 - Write a short Java method that takes an integer n...Ch. 1 - Write a short Java method that takes an integer n...Ch. 1 - Write a short Java method that counts the number...Ch. 1 - Prob. 9RCh. 1 - Prob. 10R
Ch. 1 - Modify the CreditCard class from Code Fragment 1.5...Ch. 1 - Prob. 12RCh. 1 - Modify the declaration of the first for loop in...Ch. 1 - Prob. 14CCh. 1 - Write a pseudocode description of a method for...Ch. 1 - Write a short program that takes as input three...Ch. 1 - Write a short Java method that takes an array of...Ch. 1 - Prob. 18CCh. 1 - Write a Java program that can take a positive...Ch. 1 - Write a Java method that takes an array of float...Ch. 1 - Write a Java method that takes an array containing...Ch. 1 - Prob. 22CCh. 1 - Write a short Java program that takes two arrays a...Ch. 1 - Modify the CreditCard class from Code Fragment 1.5...Ch. 1 - Modify the CreditCard class to add a toString()...Ch. 1 - Write a short Java program that takes all the...Ch. 1 - Write a Java program that can simulate a simple...Ch. 1 - A common punishment for school children is to...Ch. 1 - The birthday paradox says that the probability...Ch. 1 - (For those who know Java graphical user interface...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
When complete, the following program skeleton will search for the string Windy in the array place. If place con...
Starting Out with C++ from Control Structures to Objects (9th Edition)
This operator connects two Boolean expressions into one. One, and only one, of the expressions must be true for...
Starting Out With Visual Basic (7th Edition)
Fill in the blanks in each of the following: Types in Java are divided into two categoriestypes and types.
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Now add the following in the Code Pad: TicketMachinet2=t1; What would you expect a call to t2.getBalance() to r...
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Stadium Seating There are three seating categories at an athletic stadium. For a baseball game, Class A seats c...
Starting out with Visual C# (4th Edition)
A superclass has the following method: public void setValue( int v) { value = v; } Write a statement that may a...
Starting Out with Java: Early Objects (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
- FOR JAVA Write a method that takes a two dimensional integer array, and returns the number of elements in it. Note that your method should also work with nonrectangular arrays such as {{1}, {2, 3}, {4, 5, 6}}.arrow_forwardWrite a Java method that takes an array of float values and determines if all the numbers are different from each other (that is, they are distinct).arrow_forwardWrite a simple java delcaration for an array of double values name a. Do not allocate space for the elements of the array.arrow_forward
- Write a Java program to find continuous sub array of the given array whose sum is equal to a given number. For example, If {12, 5, 31, 9, 21, 8} is the given array and 45 is the given number, then you have to find continuous sub array in this array such that whose elements add up to 45. In this case, {5, 31, 9} is such sub array whose elements add up to 45.arrow_forwardWrite a program in java in which we had an array and you have to find Whether this array is monotonic or notarrow_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_forward
- Write and test a Java method minimum() that returns the minimum of an array of n integers.arrow_forwardWrite a Java program tat prompts user for a list of integers with 0 as the last value.Save the values in an array. Assume there can be maximum 100 values. Theprogram should have the following methods:- A method that takes the array as parameter and updates each value in thearray to the square of the value.- Another method that takes the original and modified arrays as parametersand displays the original and the squared values.arrow_forwardhelp asaparrow_forward
- 6. In Java Write a static method transpose() that receives as parameter, a 2D square array numArof integers, and swaps the row and column of each element. For example:6 7 8 0 6 3 1 23 2 4 5 → 7 2 5 01 5 8 2 8 4 8 92 0 9 3 0 5 2 3Hint: Once you find the largest-sum column, you will need to swap its entries with the first column,element-by-element.arrow_forwardWrite a Java method that takes two 2 dimensional int arrays (a and b) anda 2 dimensional boolean array (c) where all three arrays have the samesize. Your method should return an array (result) such that, if a particular element in c is true, then the corresponding (same indexed) elementin result must be the multiplication of the the corresponding elements ofa and b. If the element in c is false, then the the corresponding elementin result must be the negative of multiplication of the the correspondingelement in a and b.arrow_forwardComplete the following method in java that takes an array and a key(int value) that traverses the input parameter array with a nested for loop and finds the number of pairs of the numbers in the array that add up to the val(key) parameter. I'm not sure if this is correct: public static int nestedLoopsTwoSum(int[] X, int val) {int count = 0;for (int i = 0; i < X.length; i++){int k;for (k = 0; k < i ; k++){if ((X[i] + X[k]) == val){count++;}}}return count;}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