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
A(n application system is the master controller for all the activities that take place within a computer system. _______________
Elenna [48]
The answer is b.false
3 0
3 years ago
The company generates a lot of revenue and is rapidly growing. They're expecting to hire hundreds of new employees in the next y
uysha [10]

Answer:

The most appropriate way to deal with the situation presented above is to acquire more space at the current office site at additional rent beforehand.

Explanation:

The Scaling of a revenue-generating business is a crucial task in which a lot of pre-planning and thinking is required.

In order to scale the business in the next year, the planning of it is to be carried out at the moment and proper necessary arrangements are ensured. These steps could be one from:

  • Looking for bigger spaces for renting for a full shift of the operations
  • Looking for a site office for an additional office
  • Acquiring more space in the current office site.

This process would result in acquiring a bigger place beforehand but in order to mitigate the risk, try to keep the place in view by providing them a bare minimum advance for the additional units.

8 0
3 years ago
Uses of the following button in a keyboard: Prt SC, Home, Shift, Tab, Pg Up.​
creativ13 [48]

Answer:

This Print Screen key is used to take the screenshots of all that is appearing on the screen, and this can then be pasted in paint and saved in some location of the computer.

The Home key takes the cursor from the current position to the top left, or the start of the file.

Shift: There are two shift keys. And they are used to print the character in the capital. And when the caps lock is busy it can be used to print in lower case. It is also used together with arrow keys to select a part of the text.

Tab: This key moves the cursor from the current location to the location which we know as tab stops ( and the very next one).

Pg Up:​ The page up is being used for scrolling up, and the distance to which limit the scrolling will take place depends upon the application you are working on.

Explanation:

Please check the answer.

4 0
3 years ago
The main trade-off that all investors must consider is
Talja [164]
<span>The main trade-off that all investors must consider is Risk vs Return
In the end, all the techniques that implemented in investing process is aimed for nothing other than profit.
Current market trend dictates that potential return tend to be higher the riskier the investment is and vice versa.
</span>
3 0
3 years ago
Read 2 more answers
In the output at the command line from a router that reads - ip ospf message-digest-key 1 md5 CISCO-123 - what does the CISCO-12
11111nata11111 [884]

Answer: a) it is used as a password.

Explanation:

In order to be able to exchange routing information , CISCO routers use an authentication process, so when they send a message (a HELLO message for instance) the router that receives the message confirms that the message is authentic.

There are several types of authentication in OSPF, null, plain  and MD5.

The difference between them is as follows:

1) null, implies that no password is included in the packet header, it's the default mode.

2) plain: In this type of authentication, the password is sent transparently from a router to his neighbor, as a plain text which makes it vulnerable to attacks from packet inspection software, like Sniffer.

3) MD5, is a more secure mode, in which the password is not sent directly, but a hash built based on the packet contents and the password itself instead.

MD5 (Message Digest 5) is the name of the algoritm used to build the hash that receiver will compare with the sent by the sender in order to confirm authentication.

The chosen password, is placed at the end of the command, after the type of authentication (MD5 in this case), which in this case is "CISCO-123".  

7 0
3 years ago
Other questions:
  • A short-term job or work project that can be paid or unpaid and can lead to a full-time, paying position is called a(n) _____.
    5·2 answers
  • A modern information-processing model that views memories as emerging from particular activation patterns within neural networks
    6·1 answer
  • So how do I repost a answer that I already answered to a question because I answered this question but later it told me to repos
    14·1 answer
  • Where will the CPU store data for easy access and quick retrieval during these computations?
    13·1 answer
  • Imagine the user types in a complete sentence, but we want to read only the first word and place it in the String variable word.
    11·1 answer
  • Using PowerPoint or Impressed guarantees that your presentation will do which of the following?
    6·1 answer
  • Write a program that defines an array of integers and a pointer to an integer. Make the pointer point to the beginning of the ar
    12·1 answer
  • ________ are the symbolic codes used in assembly language?​
    6·1 answer
  • Define operating system?explain the types of operating system on the basis of use.​
    7·1 answer
  • How to make text icome one word at a timen filmora
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!