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
Question
Chapter 30.3, Problem 30.3.1CP
Program Plan Intro
Purpose of given code:
Purpose of given code is to implements the aggregate operations for “IntStream”, “LongStream”, and “DoubleStream” for processing primitive “int”, “long”, and “double” values.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
int binsearch (int X , int V [] , int n )
{
int low , high , mid , i ;
low = 0;
high = n - 1;
for ( i = 0; i < high ; i ++)
{
if( V[ i ] > V [ i +1])
return -2;
}
while ( low <= high )
{
mid = ( low + high )/2;
if ( X < V [ mid ])
high = mid - 1;
else
if ( X > V [ mid ])
low = mid + 1;
else
return mid ;
}
return -1;
}
This code takes as input a sorted array V of size n, and an integer X, if X exists in the array it will return the index of X, else it will return -1.
1. Draw a CFG for binsearch().
2. From the CFG, identify a set of entry–exit paths to satisfy the complete statement coverage criterion.
3. Identify additional paths, if necessary, to satisfy the complete branch coverage criterion.
4. For each path identified above, derive their path predicate…
public class testRun{public static int find(int[] data, int target,int start, int end) {int[] stored = sort(data);if (start <= end) {int midPoint = (start + end / 2);if (stored[midPoint] == target) {return midPoint;}if (stored[midPoint] > target) {return find(data, target, start, midPoint - 1);//return first half,exclusive itself}if (stored[midPoint] < target) {return find(data, target, start, midPoint + 1);//return last half,exclusive itself.}}return -1;}public static int[] sort(int[] data){// Find the smallest element in the listfor (int i = 0; i < data.length -1 ; i++){ //generate the index position,not =< b/c goes outer boundint min = i; //assign index position to min in each iterationfor (int j = i + 1; j < data.length ; j++){if (data[j] < data[min]){ //if the element in the second index number smaller than// the element in previous index numbermin = j; // assign j to the smallest number}}swap (data,i,min);// data[i] = min the smallest number assign to…
void doo(list &L){
int item,a,p=L.size()-1; L.retrieve(p,a);
for(int i=0;i
Chapter 30 Solutions
Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
Ch. 30.1 - Prob. 30.1.1CPCh. 30.2 - Prob. 30.2.1CPCh. 30.2 - Prob. 30.2.2CPCh. 30.2 - Prob. 30.2.3CPCh. 30.2 - Prob. 30.2.4CPCh. 30.3 - Prob. 30.3.1CPCh. 30.3 - Prob. 30.3.2CPCh. 30.3 - Prob. 30.3.3CPCh. 30.3 - Prob. 30.3.4CPCh. 30.3 - Given an array names in Listing 30.1, write the...
Ch. 30.4 - Prob. 30.4.1CPCh. 30.4 - How do you create a parallel stream?Ch. 30.4 - Prob. 30.4.3CPCh. 30.4 - Prob. 30.4.4CPCh. 30.4 - Prob. 30.4.5CPCh. 30.4 - Write a statement to obtain an array of 1000...Ch. 30.5 - Prob. 30.5.1CPCh. 30.5 - Prob. 30.5.2CPCh. 30.5 - Prob. 30.5.3CPCh. 30.5 - Prob. 30.5.4CPCh. 30.6 - Prob. 30.6.1CPCh. 30.7 - Prob. 30.7.1CPCh. 30.8 - Can the following code be used to replace line 19...Ch. 30.8 - Prob. 30.8.2CPCh. 30.8 - Prob. 30.8.3CPCh. 30.8 - Prob. 30.8.4CPCh. 30.8 - Write the code to obtain a one-dimensional array...Ch. 30 - Prob. 30.1PECh. 30 - Prob. 30.2PECh. 30 - Prob. 30.3PECh. 30 - (Print distinct numbers) Rewrite Programming...Ch. 30 - Prob. 30.5PECh. 30 - Prob. 30.6PECh. 30 - Prob. 30.7PECh. 30 - Prob. 30.8PECh. 30 - Prob. 30.9PECh. 30 - Prob. 30.10PECh. 30 - Prob. 30.11PECh. 30 - (Sum the digits in an integer) Rewrite Programming...Ch. 30 - (Count the letters in a string) Rewrite...Ch. 30 - Prob. 30.14PECh. 30 - (Display words in ascending alphabetical order)...Ch. 30 - Prob. 30.16PECh. 30 - Prob. 30.17PECh. 30 - (Count the occurrences of words in a text file)...Ch. 30 - (Summary information) Suppose the file test.txt...
Knowledge Booster
Similar questions
- void getInput(){for(int i =0; i < studentName.length; i++){System.out.print("Student name: ");studentName[i] = keyboard.nextLine();System.out.print("Studnet ID: ");midTerm1[i] = keyboard.nextInt();}keyboard.close();} Can't put full student name becuase nextLine();arrow_forwardDetermine the output.namespace DataStructures{class Program{static void Main(string[] args){int[] myArray = { 1, 3, 2, 4 };Sort(myArray, 0, myArray.Length - 1);}static void Sort(int[] myArray, int left, int right){if ((right - left) >= 1){int middle1 = (left + right) / 2;int middle2 = middle1 + 1;DisplayArray(myArray, left, right);DisplayArray(myArray, left, middle1);DisplayArray(myArray, middle2, right);Console.WriteLine("___________________________________________");Sort(myArray, left, middle1);Sort(myArray, middle2, right);Combine(myArray, left, middle1, middle2, right);} }static void Combine(int[] myArray, int left, int middle1, int middle2, int right) {int[] combined = new int[myArray.Length];int leftindex = left;int rightindex = middle2;int combinedindex = left;DisplayArray(myArray, left, middle1);DisplayArray(myArray, middle2, right);while (leftindex <= middle1 && rightindex <= right){if (myArray[leftindex] > myArray[rightindex])combined[combinedindex++] =…arrow_forwarddef determineHours(): with open ("StudyHours.txt", "r") as file1: data = file1.readlines() total_study_hours = 0 for i, line in enumerate(data): if "error" in line: print(f"Error found in line {i + 1}: {line}") correct = input("Do you want to correct this line?(y\n)") if correct == "y": new_line = input("Enter corrected line:") data[i]=new_line for record in data: fields = record.strip().split(',') name = fields[0].title() credits = int(fields[1]) grade = fields[2] if grade == 'A':#determine weekly study hours based on desired grade study_hours = 15 * credits elif grade == 'B': study_hours = 12 * credits elif grade == 'C': study_hours = 9 * credits elif…arrow_forward
- def strPattern(mystr): lenght = len(mystr) mystr1 = "" for i in range(lenght - 1): mystr1 = mystr1 + mystr[i].upper() + str(i + 1) if lenght == 0: return mystr1 return mystr1 + mystr[-1].upper() s = input("enter a word: ") print(strPattern(s)) s = input("enter a word: ") EOFError: EOF when reading a line how can i fix this errorarrow_forwardWrite a program that generates a square table that contains randomly generated integer values that are between 0 and10. - include a fixed seed value by using the function random.seedarrow_forwardvoid countSort(int arr[], int n, int exp) { intoutput[n]; inti, count[10] = { 0 }; for (i=0; i<n; i++) count[(arr[i] /exp) %10]++; for (i=1; i<10; i++) count[i] +=count[i-1]; for (i=n-1; i>=0; i--) { output[count[(arr[i] /exp) %10] -1] =arr[i]; count[(arr[i] /exp) %10]--; } for (i=0; i<n; i++) arr[i] =output[i]; } Can I get this C code in MIPS programming language?arrow_forward
- function loginValidate () { var id = document.getElementById ('myid').value; var pass = document.getElementById('mypassword').value; if ((id == null : id alert ("ID and Pasword both must be filled out") : "") && (pass == null , pass == ")){ == return false: else if (id == null || id == "") { alert ("ID must be filled out "); return false; else if (pass == null || pass == "") { alert ("Password must be filled out "); return false;arrow_forwardAdd a loop over to this function that tracks how many times the sum functions is called. Also explain how the loop is working. int64_t sum(int64_t N, uint64_t A[]){ int64_t sum = 0; uint64_t indx = A[0]; for (int64_t i = 0; i < N; i++){ sum += A[indx]; indx = A[indx]; } return sum;}arrow_forwardI have a dataset numbers=load('mytextfile') Output numbers = struct with fields: train0: [5923×784 uint8]test0: [980×784 uint8]train1: [6742×784 uint8]test1: [1135×784 uint8]train2: [5958×784 uint8]test2: [1032×784 uint8]train3: [6131×784 uint8]test3: [1010×784 uint8]train4: [5842×784 uint8]test4: [982×784 uint8]train5: [5421×784 uint8]test5: [892×784 uint8]train6: [5918×784 uint8]test6: [958×784 uint8]train7: [6265×784 uint8]test7: [1028×784 uint8]train8: [5851×784 uint8]test8: [974×784 uint8]train9: [5949×784 uint8]test9: [1009×784 uint8] How do I apply one hot coding to this dataset? I am coding in matlabarrow_forward
- Write only the function definition: Implement the following function definition: int CrazyWord(char word [ ]); //input: a character array with a null character (string) //sets all of the characters in the word to lowercase letters //changes any lowercase ‘o’ letters to hashtags ‘#’ //returns the number of hashtags that are now in the wordarrow_forwardIn C++, finish the Robot Paths code. Here is the starter code: int paths(int i, int j) { static int p[5][5] = {0}; if (i == 0 || j == 0) return 1; if (p[i][j] != 0) return p[i][j]; return paths(i, j-1) + paths(i-1, j);}arrow_forwardINSTRUCTION: make this a flowchart import java.util.HashSet;import java.util.Scanner;import java.util.Set; public class elements { public static void main(String args[]) { Scanner sc = new Scanner(System.in); // Creating two sets Set<Integer> set1 = new HashSet<Integer>(); Set<Integer> set2 = new HashSet<Integer>(); System.out.println("Enter the element of set A [max-5 elements]: "); for (int i = 0; i < 5; i++) { int num = sc.nextInt(); set1.add(num); } System.out.println("Enter the element of set B [max-5 elements]: "); for (int i = 0; i < 5; i++) { int num1 = sc.nextInt(); set2.add(num1); } // creating a menu of opeartions System.out.println("a. Identify elements of set"); System.out.println("b. Check Union"); System.out.println("c. Check Difference"); System.out.println("d. Check Intersection"); System.out.println("e. Check Subset"); System.out.println("f. If set A and B are…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