Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please when u answer type question aswell waited for so long someone gave wrong answers! JV_UIHWUSCH-giP8dD import java.util.Arrays; 2 public class Example1 4 v{ 3

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
please when u answer type question aswell waited for so long someone gave wrong answers!
JV_UIHWUSCH-giP8dD import java.util.Arrays; 2 public class Example1 4 v{ 3 public static void main(String args[]) { int arr[] = { 1, 3, 4, 2, 7, 5, 8, 6, 10 }; int var = arr.length; 5 v 6. %3D 8. System.out.println(foo(arr, var)); 9. 10 11 v public static double foo(int a[], int n) { Arrays.sort(a); 12 13 if (n % 2 != 0) { return (double)a[n / 2]; 14 v 15 16 17 18 return (double)(a[(n - 1) / 2] + a[n / 2]) / 2.0; 19 20 Hwu5cnFglP8dD 17 18 return (double)(a[(n - 1) / 2] + a[n/ 2]) / 2.0; } 19 20 } Choose Yes or No for each of the code summaries below if they correctly summarize the above code snippet. return the median position number of an array. Yes No No The code initialises an array and calls the foo function sending the array and its length. The foo function sorts the array and checks the length. If the length of the array is an odd number it return the element at the length/2 index of the sorted array Yes No it is used to find the median in an array Yes No starts with an array with 9 elements, then sorts the array. Then checks if n (length of array) is even or odd. if odd, it will return the element in the middle left. else, it will return, the element in the middle, just using a different formula since an array with even number does not have a true middle. Yes No The code computes median in an array. Yes No

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Database Technology Edbt 88 International Conference On Extending Database Technology Venice Italy March 14 18 1988 Proceedings Lncs 303

Authors: Joachim W. Schmidt ,Stefano Ceri ,Michele Missikoff

1988th Edition

3540190740, 978-3540190745

More Books

Students also viewed these Databases questions

Question

1. What are the pros and cons of diversity for an organisation?

Answered: 1 week ago

Question

1. Explain the concept of diversity and equality in the workplace.

Answered: 1 week ago