1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
In-s [12.5K]
3 years ago
15

Write a function called median, that takes as parameter a full, sorted array of doubles and returns the median of the list. For

a sorted list of odd length, the median is the middle value. For a sorted list of even length, the median is the average of the two middle values. Make an example function call in your main. Write a function called isSorted that takes an array of doubles as a parameter and returns true if the list is in sorted (non-decreasing) order and returns false otherwise. Make an example function call in your main. Write a function called findCommon that takes three arrays of positive integers as parameters. The first two array parameters are filled with ints. Fill the third array parameter with all the values that are uniquely in common from the first two arrays and the rest of the array with zeros. For example:

Computers and Technology
1 answer:
trapecia [35]3 years ago
8 0

Answer:

Explanation:

public class Lab8

{

public static double median(double list[])

{

int size=list.length;

if(size%2!=0)

return list[size/2];

else

return(list[size/2-1]+list[size/2])/2.0;

}

public static boolean issorted(double list[])

{

for(int i=0;i<list.length-1;i++)

{

if(list[i]>list[i+1])

return false;

}

return true;

}

public static void findcommon(int a1[],int a2[],int common[])

{

int c=0;

for(int i=0;i<a1.length;i++)

{

boolean isFilled=false;

for(int j=0;j<c;j++)

{

if(a1[i]==common[j])

{

isFilled=true;

break;

}

}

if(isFilled)

{

for(int k=0;k<a2.length;k++)

{

if(a1[i]==a2[i])

{

common[c]=a1[i];

c++;

break;

}

}

}

}

while(c<common.length)

{

common[c]=0;

c++;

}

}

public static void rotateRight(int list[])

{

int temp=list[list.length-1];

for(int i=list.length-1;i>0;i--)

{

list[i]=list[i-1];

}

list[0]=temp;

}

public static int count(int list[],int n)

{

int ncount=0;

for(int i=0;i<list.length;i++)

{

if(list[i]==n)

ncount++;

}

return ncount;

}

public static int[] stretch(int list[])

{

int stretchedList[]=new int[list.length*2];

int k=0;

for(int i=0;i<list.length;i++)

{

int n=list[i];

if(n%2==0)

{

stretchedList[k]=n/2+1;

stretchedList[k+1]=n/2;

}

k+=2;

}

return stretchedList;

}

public static void printDoubleArray(double arr[])

{

System.out.print("[");

for(int i=0;i<arr.length;i++)

{

if(i!=arr.length-1)

System.out.print(arr[i]+",");

else

System.out.print(arr[i]);

}

System.out.println("]");

}

public static void printIntArray(int arr[])

{

System.out.print("[");

for(int i=0;i<arr.length;i++)

{

if(i!=arr.length-1)

System.out.print(arr[i]+",");

else

System.out.print(arr[i]);

}

System.out.println("]");

}

public static void main(String[] args)

{

double list1[]={1.1,2.2,3.3,4.4,5.5,6.6};

double med=median(list1);

System.out.println("List1:");

printDoubleArray(list1);

System.out.println("Median of List1:"+ med);

double list2[]={1.1,2.2,3.3,4.4,6.6,5.5};

boolean result=issorted(list2);

System.out.println("List2:");

printDoubleArray(list2);

System.out.println("List2 is a sorted array.(T/F):"+ result);

int list3[]={3,8,5,6,5,8,9,2};

int list4[]={5,15,4,6,7,3,9,11,9,3,12,13,14,9,5,3,13};

int list5[]=null;

if(list3.length<=list4.length)

list5=new int[list3.length];

else

list5=new int[list4.length];

findcommon(list3,list4,list5);

System.out.println("\n List3:");

printIntArray(list3);

System.out.println("\n List4:");

printIntArray(list4);

System.out.println("\n Array with common value,List5:");

printIntArray(list5);

int list6[]={3,8,19,7};

System.out.println("\n List6:");

printIntArray(list6);

rotateRight(list6);

System.out.println("\n the array after rotate right:");

printIntArray(list6);

int list7[]={3,5,2,1,92,38,3,14,5,73};

int n=count(list7,3);

System.out.println("\n List7:");

printIntArray(list7);

System.out.println("\n the number of occurences of the value 3 in the list 7:"+ n);

int list8[]={18,7,4,24,11};

int list9[]=stretch(list8);

printIntArray(list8);

System.out.println("\n The array after stretching:");

printIntArray(list9);

}

}

You might be interested in
For python how do I ask the user how many numbers they want to enter and then at the ending add those numbers up together?
Digiron [165]

I am not too familiar with the Python language, but the algorithm would be something like this:

1. create a variable for the sums of the number

2. read in how many numbers the user wants to enter (let's call it N)

and then create a for loop:

for N times

read in the next number

increase the sum variable by that number

Hopefully this helps!

8 0
3 years ago
Which access control principle limits a user's access to the specific information required to perform the currently assigned tas
Svetradugi [14.3K]

Answer:

The answer is "Need-To-Know Access Control Principle"

Explanation:

There are three types of access control methods such as Role-Based Access Control, Discretionary Access Control and Mandatory Access Control.

The access control principle that limits/blocks the user from gaining access to a folder/information/procedure within the system is called "Need-To-Know Access Control Principle".

I hope this answer helps.

4 0
3 years ago
Concept of CPU scheduler?​
vekshin1

Answer:

CPU scheduling is a process which allows one process to use the CPU while the execution of another process is on hold(in waiting state) due to unavailability of any resource like I/O etc, thereby making full use of CPU. ... The selection process is carried out by the short-term scheduler (or CPU scheduler).

6 0
3 years ago
Which term describes the distinct number of colors a graphic contains? (1 point)?
laila [671]
Your answer would be "Hue".
4 0
3 years ago
You've added a clip art image to your slide. Now you want to add a border. Which tab would you use to make this change?
Vinvika [58]
<span>If you want to add a border you have to use 'Insert' tab to make this change. Then you have to click on</span> "Picture" that is placed in the Insert menu, and choose "Clip Art." You can use the search box at the top of the Clip Art gallery in order to find a suitable border. When you finally found it, click on it, then select the button "Insert".
6 0
3 years ago
Read 2 more answers
Other questions:
  • Your dad just purchased a new desktop with Windows 8 Professional. He is calling you, informing you that he is unable to remote
    9·1 answer
  • Jana keeps receiving friend requests from strangers on a social media site. This is making her uncomfortable.
    15·2 answers
  • A device capable of copying a graphic, document, or other object is called a
    7·2 answers
  • BI is an umbrella term that combines architectures, tools, databases, analytical tools, applications, and methodologies. b. BI i
    10·1 answer
  • What is this I’m so lost
    9·1 answer
  • python Write a program that will take a file named Celsius.dat that contains a list of temperatures in Celsius (one per line), a
    9·1 answer
  • a(n) ___ loop allows you to cycle through an array without specifying the starting and ending points for the loop
    14·1 answer
  • Subana is writing a program which will calculate the mean average of a set of numbers by adding the numbers and dividing the res
    11·2 answers
  • Statement Widgets or gadgets are _____ programs that appear on the desktop and display little pieces of information such as a ca
    5·1 answer
  • PLZ HELP What will be the output? class num: def init (self.a): self. number = a mul* __(self. b) return self. number + b. numbe
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!