Data Structures and Algorithms in Java
6th Edition
ISBN: 9781118771334
Author: Michael T. Goodrich
Publisher: WILEY
expand_more
expand_more
format_list_bulleted
Question
Chapter 1, Problem 14C
Program Plan Intro
Reverse an array of n integers
Pseudocode:
Input: Array A Size of array n
Output: Array which is reverse of input array A
/*Call the Reverse method to reverse the array of integers*/ Reverse(A, n) //Declare the start and end variables Start = 0 and end = n-1 /*Execute the while loop until the condition leads to false*/ While (start < end) //Declare a temporary variable Temp=0; //Perform swapping Temp= A[start] A[start]= A[end] A[end]=Temp //increment the start and decrement the end start++ and end -- // end of while loop
Expert Solution & Answer
Learn your wayIncludes step-by-step video
schedule03:32
Students have asked these similar questions
Write a program in java in which we had an array and you have to find Whether this array is monotonic or not
Write a program in java that prints an array using one loop even if it's a 2 dimentional array while using recursion. Include the main program and a sample and all.
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.
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...
Knowledge Booster
Similar questions
- Write 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 java method that receives a reference to an array of integers and then sorts only the non-perfect numbers. if a number is perfect then it must remain in its current location in the array. Notes: 1) You are not allowed to use the Arrays.sort() method or any other ready-made sorting method. 2) You can not define new arrays. Your sorting must be in-place. 3) A number if perfect if the some of its divisors is equal to the number itself. For example the number 6 is perfect because the sum of its divisors is 1+2+3 = 6 while 8 is not perfect because the sum of its divisors is 1+2+4 = 7 which is not equal to 8.arrow_forwardWrite a java method that receive a reference to an array of integers and then prints only the prime numbers which their locations in the array are not contiguous(i.e. non-prime numbers must remain in their locations, and prime numbers which are not contiguous must be sorted ). Note: you can not define new arrays. (i.e. You have to do the sorting job in-place) Example: 4 7 5 6 8 3: 7 and 5 are contiguous which 5 and 3 are not contiguousarrow_forward
- Write a Java program that expands a given binomial (x + y)^n, where integer n is user input. To do the work of the binomial expression, first create a method that accepts n as a parameter and then returns an array holding the coefficients needed for the binomial expansion using the Pascal’s Triangle method. Create a 2nd method which takes the array holding the coefficients as a parameter and prints the appropriate binomial expansion. For example, if n = 5 is entered by the user, the method calculating the coefficients should return {1,5,10,10,5,1} and the method that prints the expansion should print the following: (x + y)^5 = x^5 + 5x^4y + 10x^3y^2 + 10x^2y^3 + 5xy^4 + y^5 Your main method should use an appropriate loop for repeated inputs and automatically call the methods to calculate the coefficients and print the binomial expansion. There isn’t a need for a menu although you should ask the user if they want to quit or continue after their binomial expansion is printed each time.…arrow_forwardWrite a java program to declare an array of 20 integers and initialize all of its members with 7. Print the array.arrow_forwardUse java.arrow_forward
- Write a java method that receives a reference to an array of integers and then prints only the perfect numbers which their locations in the array are not contiguous. Note: you can not define new arrays. Example: if the array contains the numbers: 4 28 6 8 496 3 then the output will be: 6 496 28 is a perfect number but it is not in the output because 6 is contiguous to itarrow_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_forwardWrite a Java method (do not write a class, only the method) with the following signature: Return type: void Parameters: 2D integer array Name: printDiagonal Implement the method code that will print out the values of the 2D array along the Diagonal from left to right. For example, if the array had the following values: 56 78 98 21 33 55 98 44 11 The method should print to the console: 56,33,11 The above 2D array example is only given for you to understand the problem Do not hard code the values in your solution or assume the array is the same as the given data. Your method should work for all 2D integer arrays.arrow_forward
- Write a JAVA method that takes three inputs. The first input is a 2d array of integers, the second and third inputs are integers to be used to index rows of the array. Fill in the code in the method so that it swaps the values in the indexed rows.Example method header:public static void rowSwap(int[][] array, int row1, int row2) Example input and output:INPUT:array = {7, 6, 2}, {0, 8, 3}, {5, 5, 1};row1 = 0;row2 = 2;OUTPUT:nothing is returned, but the array now references the following data in memoryarray = {5, 5, 1}, {0, 8, 3}, {7, 6, 2};arrow_forwardWrite a recursive method that gets three parameters as input: an array of integers called nums, an integer called index,and an integer called The purpose of this method is to return true if value is stored in the array starting at nums[index]. That is, you have to check if value is equal to nums[index] or nums[index +1] or nums[index +2 ] …. nums[nums.length -1]. Do not use loops.(java code)arrow_forwardhelp asaparrow_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