Concept explainers
Assume this code is using the IntBinarySearcher class presented in this chapter:
Int[] numbers = {8, 0, 9, 4, 3, 7, 2};
// Search for 7.
int location = IntBinarySearcher.search(numbers, 7);
// Display the result.
if (location != -1)
System.out.println("7 was found in the array.");
else
System.out.println("7 was NOT found in the array.");
Want to see the full answer?
Check out a sample textbook solutionChapter 16 Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Additional Engineering Textbook Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
INTERNATIONAL EDITION---Engineering Mechanics: Statics, 14th edition (SI unit)
Starting Out With Visual Basic (8th Edition)
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Concepts Of Programming Languages
Web Development and Design Foundations with HTML5 (8th Edition)
- 1. Shift Left k Cells Use Python Consider an array named source. Write a method/function named shiftLeft( source, k) that shifts 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] shiftLeft(source,3) After calling shiftLeft(source,3), printing the array should give the output as: [ 40, 50, 60, 0, 0, 0 ]arrow_forward2. The reserve method reserves an array by copying it to a new array. Rewrite the method that reverse the array passed in the argument and returns this array. Write a test program that prompts the user to enter ten numbers, invokes the method to reverse the numbers and displays the numbers.arrow_forwardWrite code for PersonManagement class. This class contains the array of Person class (code is given below) and also following methods:1. set: This method receives the array of person class and set the attribute.2. displayAll: This method will display values of all persons.3. sort: This method will sort the array according to age values of the persons with ascending order using Selection Sort.4. reverse: This method will reverse the order of the array.5. getPersons: This method will return the array of the persons (attribute).6. displayEvenAgePerson: This method will display all those persons values who have even age.7. displayOddAgePerson: This method will display all those persons values who have odd age.8. displayPrimeAgePerson: This method will display only those persons values who have prime number age.Following is the class of Person: public class Person {private String Name;public int age;public void set(String Name, int age){this.Name = Name;if(age > 0 && age <=…arrow_forward
- For the array ADT, the operations associated with the type array are: insert a value in the array, delete a value from the array, and test whether a value is in the array or not. 1.true 2.falsearrow_forwardv Question Completion Status: Attach File Browse My Computer QUESTION 2 Write a Java program that creates an array of input n (get the input from the user) random integer numbers between 10 and 79 inclusive, and pass the array to a method named countAboveAverage that return integer. In this method, count the array elements that are above or equal to average and return the count. Display the returned count in main method. Finally print the n random numbers, Average, Above or equal to Average count and Below Average count. (use formula: n- countAboveAverage) Here is a sample run: Enter the value of n: 10 Random numbers: 11 20 31 10 19 79 71 51 33 41 Average : 36.6 Above or equal to Average : 4 Below Average : 6 Attach File Browse My Computer Activate Win Savo All Answors Click Save and Submit to save and submit. Click Save All Answers to save all answers.arrow_forwardsolve eith java:- Write code for PersonManagement class. This class contains the array of Person class (code is given below) and also following methods: set: This method receives the array of person class and set the attribute. displayAll: This method will display values of all persons. sort: This method will sort the array according to age values of the persons with ascending order using Selection Sort. reverse: This method will reverse the order of the array. getPersons: This method will return the array of the persons (attribute). displayEvenAgePerson: This method will display all those persons values who have even age. displayOddAgePerson: This method will display all those persons values who have odd age. displayPrimeAgePerson: This method will display only those persons values who have prime number age. Following is the class of Person: public class Person { private String Name; public int age; public void set(String Name, int age) {…arrow_forward
- Using oop in java Write code for PersonManagement class. This class contains the array of Person class (code is given below) and also following methods: set: This method receives the array of person class and set the attribute. displayAll: This method will display values of all persons. sort: This method will sort the array according to age values of the persons with ascending order using Selection Sort. reverse: This method will reverse the order of the array. getPersons: This method will return the array of the persons (attribute). displayEvenAgePerson: This method will display all those persons values who have even age. displayOddAgePerson: This method will display all those persons values who have odd age. displayPrimeAgePerson: This method will display only those persons values who have prime number age. Following is the class of Person: publicclass Person { private String Name; publicintage; publicvoid set(String Name, intage) {…arrow_forwardWrite code for PersonManagement class. This class contains the array of Person class (code is given below) and also following methods: set: This method receives the array of person class and set the attribute. displayAll: This method will display values of all persons. sort: This method will sort the array according to age values of the persons with ascending order using Selection Sort. reverse: This method will reverse the order of the array. getPersons: This method will return the array of the persons (attribute). displayEvenAgePerson: This method will display all those persons values who have even age. displayOddAgePerson: This method will display all those persons values who have odd age. displayPrimeAgePerson: This method will display only those persons values who have prime number age. Following is the class of Person: public class Person { private String Name; public int age; public void set(String Name, int age) { this.Name =…arrow_forwardWrite code for PersonManagement class. This class contains the array of Person class (code is given below) and also following methods: set: This method receives the array of person class and set the attribute. displayAll: This method will display values of all persons. sort: This method will sort the array according to age values of the persons with ascending order using Selection Sort. reverse: This method will reverse the order of the array. getPersons: This method will return the array of the persons (attribute). displayEvenAgePerson: This method will display all those persons values who have even age. displayOddAgePerson: This method will display all those persons values who have odd age. displayPrimeAgePerson: This method will display only those persons values who have prime number age.arrow_forward
- JAVA PROGRAM Chapter 7. PC #16. 2D Array Operations Write a program that creates a two-dimensional array initialized with test data. Use any primitive data type that you wish. The program should have the following methods: • getTotal. This method should accept a two-dimensional array as its argument and return the total of all the values in the array. • getAverage. This method should accept a two-dimensional array as its argument and return the average of all the values in the array. • getRowTotal. This method should accept a two-dimensional array as its first argument and an integer as its second argument. The second argument should be the subscript of a row in the array. The method should return the total of the values in the specified row. • getColumnTotal. This method should accept a two-dimensional array as its first argument and an integer as its second argument. The second argument should be the subscript of a column in the array. The method should return the…arrow_forwardplease help me with this JAVA Programming challenge from chapter 7. Below is the challenge question Thank you 17. 2D Array Operations Write a program that creates a two-dimensional array initialized with test data. Use any primitive data type that you wish. The program should have the following methods: getTotal. This method should accept a two-dimensional array as its argument and return the total of all the values in the array. getAverage. This method should accept a two-dimensional array as its argument and return the average of all the values in the array. getRowTotal. This method should accept a two-dimensional array as its first argument and an integer as its second argument. The second argument should be the subscript of a row in the array. The method should return the total of the values in the specified row. getColumnTotal. This method should accept a two-dimensional array as its first argument and an integer as its second argument. The second argument should be the…arrow_forwardX462: Arrays - Find Min Write The Method FindMin That Will Return The Smallest Number In An Array Of Integers.arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage