Java: An Introduction to Problem Solving and Programming (7th Edition)
7th Edition
ISBN: 9780133766264
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 7, Problem 15E
Write a static method for selection sort that will sort an array of characters.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
A bit new to methods and need a little bit of help.
Swap Method
Your task is to write a public static method named swap that takes a single parameter which is an array of doubles. This method should swap the first and last element in the array and then return the adjusted double array.
You can assume that all arrays passed into the method are a length of 2 or more.
For example, the test data provided when passed into the swap method should go from:
{8.34, 7.221, 10.643, 93.2}
to
2. Rotate Left k cells Use Python
Consider an array named source. Write a
method/function named rotateLeft( source,
k) that rotates all the elements of the
source array to the left by 'k' positions. You
must execute the method by passing an
array and number of cells to be shifted.
After calling the method, print the array to
show whether the elements have been
shifted properly.
Example:
source=[10,20,30,40,50,60]
rotateLeft(source,3)
After calling rotateLeft(source,3), printing
the array should give the output as:
[ 40, 50, 60, 10, 20, 30]
Shift Right k Cells (Use Python)
Consider an array named source. Write a method/function named shifRight( source, k) that shifts all the elements of the source array to the right by 'k' positions. You must execute the method by passing an array and number of cells to be shifted. After calling the method, print the array to show whether the elements have been shifted properly.
Example:
source=[10,20,30,40,50,60]
shiftRight(source,3)
After calling shiftRight(source,3), printing the array should give the output as:
[ 0,0,0,10,20,30 ]
Chapter 7 Solutions
Java: An Introduction to Problem Solving and Programming (7th Edition)
Ch. 7.1 - What output will be produced by the following...Ch. 7.1 - What output will be produced by the following...Ch. 7.1 - What output will be produced by the following...Ch. 7.1 - Consider the following array: int [] a = new...Ch. 7.1 - What is wrong with the following code to...Ch. 7.1 - Write a complete Java program that reads 20 values...Ch. 7.2 - Write some Java code that will declare an array...Ch. 7.2 - Rewrite the method displayResults of the program...Ch. 7.2 - What output will be produced by the following...Ch. 7.2 - Give the definition of a static method called...
Ch. 7.2 - Give the definition of a static method called...Ch. 7.2 - Prob. 12STQCh. 7.2 - The following method compiles and executes but...Ch. 7.2 - Suppose that we add the following method to the...Ch. 7.3 - Prob. 15STQCh. 7.3 - Replace the last loop in Listing 7.8 with a loop...Ch. 7.3 - Suppose a is an array of values of type double....Ch. 7.3 - Suppose a is an array of values of type double...Ch. 7.3 - Prob. 19STQCh. 7.3 - Consider the partially filled array a from...Ch. 7.3 - Repeat the previous question, but this time assume...Ch. 7.3 - Write an accessor method getEntryArray for the...Ch. 7.4 - Prob. 23STQCh. 7.4 - Write the invocation of the method selectionSort...Ch. 7.4 - How would you need to change the method...Ch. 7.4 - How would you need to change the method...Ch. 7.4 - Consider an array b of int values in which a value...Ch. 7.5 - What output is produced by the following code?...Ch. 7.5 - Revise the method showTable in Listing 7.13 so...Ch. 7.5 - Write code that will fill the following array a...Ch. 7.5 - Write a void method called display such that the...Ch. 7.6 - Prob. 33STQCh. 7 - Write a program in a class NumberAboveAverage that...Ch. 7 - Write a program in a class CountFamiles that...Ch. 7 - Write a program in a class CountPoor that counts...Ch. 7 - Write a program in a class FlowerCounter that...Ch. 7 - Write a program in a class characterFrequency that...Ch. 7 - Create a class Ledger that will record the sales...Ch. 7 - Define the following methods for the class Ledger,...Ch. 7 - Write a static method isStrictlyIncreasing (double...Ch. 7 - Write a static method removeDuplicates(Character[]...Ch. 7 - Write a static method remove {int v, int [] in}...Ch. 7 - Suppose that we are selling boxes of candy for a...Ch. 7 - Create a class polynomial that is used to evaluate...Ch. 7 - Write a method beyond LastEntry (position) for the...Ch. 7 - Revise the class OneWayNoRepeatsList, as given in...Ch. 7 - Write a static method for selection sort that will...Ch. 7 - Overload the method selectionSort in Listing 7.10...Ch. 7 - Revise the method selectionSort that appears in...Ch. 7 - Prob. 18ECh. 7 - Write a sequential search of an array of integers,...Ch. 7 - Write a static method findFigure (picture,...Ch. 7 - Write a static method blur (double [] [] picture)...Ch. 7 - Write a program that reads integers, one per line,...Ch. 7 - The following code creates a small phone book. An...Ch. 7 - Write the method rotateRight that takes an array...Ch. 7 - The following code creates a ragged 2D array. The...Ch. 7 - Write a program that will read a line of text that...Ch. 7 - Prob. 2PPCh. 7 - Add a method bubbleSort to the class ArraySorter,...Ch. 7 - Add a method insertionSort to the class...Ch. 7 - The class TimeBook in Listing 7.14 is not really...Ch. 7 - Define a class called TicTacToe. An object of type...Ch. 7 - Repeat Programming Project 10 from Chapter 5 but...Ch. 7 - Prob. 8PPCh. 7 - Write a GUI application that displays a picture of...Ch. 7 - ELIZA was a program written in 1966 that parodied...Ch. 7 - Prob. 11PPCh. 7 - Create a GUI application that draws the following...Ch. 7 - Practice Program 2 used two arrays to implement a...Ch. 7 - Practice Program 5.4 asked you to define Trivia...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Consider the following C program void fun (void) { int a, b, c; / defiinition.1 / . . . while (. . .) int b, c,...
Concepts of Programming Languages (11th Edition)
Suppose you have two function definitions with the function declarations given in Self-Test Exercise 25. Which ...
Problem Solving with C++ (9th Edition)
Each of the following declarations or code segments has errors. Locate as many as possible. A) catch { quotient...
Starting Out with C++: Early Objects
Currency Write a program that will convert U.S. dollar amounts to Japanese yen and to euros, storing the conver...
Starting Out with C++ from Control Structures to Objects (9th Edition)
The decimal number system is a weighted system with ten digits.
Digital Fundamentals (11th Edition)
Pig Latin Write a program that accepts a sentence as input and converts each word to Pig Latin." In one version...
Starting Out with Python (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
- Write method to reverse sequence of elements in array. if you call a method with array: 1 4 9 16 9 7 4 9 11 array is converted to. this is just example 11 9 4 7 9 16 9 4 1arrow_forwardWrite the following method that sorts an ArrayList of numbers:public static void sort(ArrayList<Integer> list)Write a test program that prompts the user to enter five numbers, stores them inan array list, and displays them in increasing order.arrow_forwardJava Programming For this assignment, you are required to create a program named SelectionSortPA.java and implement selection sorting algorithm as specified below: Public static void selectionSort(int[] arr) Your main method accepts a number N from the command argument list. Then use the number N to create an N-element int array. Assign random numbers between [0, Integer.MAX_VALUE) to each of the N elements of the array. Call selectionSort method to sort the array. Display the array elements after each iteration of selection sort. Verify the array is sorted after calling your sorting method. If you implement all the required methods correctly, the driver program should generate outputs similar to the sample below:arrow_forward
- Java - Sort an Arrayarrow_forwardWrite the following method to test whether all the points in the array points are on the same line: public static boolean sameLine(double[][] points) Write a program that prompts the user to enter five points and displays whetherthey are on the same line. Here are sample runs: Enter five points: 3.4 2 6.5 9.5 2.3 2.3 5.5 5 −5 4 ↵EnterThe five points are not on the same lineEnter five points: 1 1 2 2 3 3 4 4 5 5 ↵EnterThe five points are on the same linearrow_forwardWrite the following methodthat tests whether the array has four consecutive numbers with the same value:public static boolean isConsecutiveFour(int[] values)Write a test program that prompts the user to enter a series of integers and displaysit if the series contains four consecutive numbers with the same value. Yourprogram should first prompt the user to enter the input size—i.e., the number ofvalues in the series. Here are sample runs: Enter the number of values: 8↵EnterEnter the values: 3 4 5 5 5 5 4 5↵EnterThe list has consecutive foursEnter the number of values: 9↵EnterEnter the values: 3 4 5 5 6 5 5 4 5↵EnterThe list has no consecutive foursarrow_forward
- For 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_forwardArea code processing In US, long distance phone call is made by dialing the three digits area code first, followed by 7 digits phone number The following is a list of some US area code using JavaScript code (not the most current. There are more) var AreaCode=new Array(205,251,659,256,334,907,403,780,264,268,520,928,480,602,623,501,479,870,242,246,441, 250,604,778,284,341,442,628,657,669,747,752,764,951,209,559,408,831,510,213,310,424,323,562,707,369,627, 530,714,949,626,909,916,760,619,858,935,818,415,925,661,805,650,600,809,345,670,211,720,970,303,719,203, 475,860,959,302,411,202,767,911,239,386,689,754,941,954,561,407,727,352,904,850,786,863,305,321,813,470, 478,770,678,404,706,912,229,710,473,671,808,208,312,773,630,847,708,815,224,331,464,872,217,618,309,260,317, 219,765,812,563,641,515,319,712,876,620,785,913,316,270,859,606,502,225,337,985,504,318,318,204,227,240,443, 667,410,301,339,351,774,781,857,978,508,617,413,231,269,989,734,517,313,810,248,278,586,679,947,906,616,320,…arrow_forwardTASK 1 Write a Java method that returns the index of the smallest element in an array of integers. If the number of such elements is greater than 1, return the smallest index. Use the following header: public static int indexofLargestlestelement(double[] array) Write a test program that prompts the user to enter ten numbers, invokes this method to return the index of the smallest element, and displays the index.arrow_forward
- Java: Write a complete method to create an array of random integers. Method Specification The method takes in three integer parameters: the array size, the lower bound, and the upper bound. The method also takes in a boolean parameter. The method creates and returns an integer array of the specified size that contains random numbers between the lower and upper bound., using these rules: The lower bound is always inclusive. If the boolean parameter is true, the upper bound is also inclusive. If the boolean parameter is false, the upper bound is not inclusive (meaning it is exclusive). If any of the parameters are invalid, null is returned. Driver/Tester Program I have provided you with a driver/tester program that you can use to test your code before submitting. Paste your code into the placeholder at the top of the file. Review the Homework FAQ page, which contains instructions and a video of how to use the provided file. If you aren't sure how to use the tester or have any…arrow_forwardJava: Write a complete method to create an array of random integers. Method Specification The method takes in three integer parameters: the array size, the lower bound, and the upper bound. The method also takes in a boolean parameter. The method creates and returns an integer array of the specified size that contains random numbers between the lower and upper bound., using these rules: The lower bound is always inclusive. If the boolean parameter is true, the upper bound is also inclusive. If the boolean parameter is false, the upper bound is not inclusive (meaning it is exclusive). If any of the parameters are invalid, null is returned. Driver/Tester Program I have provided you with a driver/tester program that you can use to test your code before submitting. Paste your code into the placeholder at the top of the file. I strongly recommend running this program before you submit your homework. The program is designed to help you catch common errors and fix them before submitting.…arrow_forwardThe correct syntax for passing an array as an argument in a method is: O all. a(). a. O a[0]..a[a.length].arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
9.1: What is an Array? - Processing Tutorial; Author: The Coding Train;https://www.youtube.com/watch?v=NptnmWvkbTw;License: Standard Youtube License