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 major weakness of a lot of file processing systems is that ____.
Gnesinka [82]

They are several weaknesses or disadvantages of file processing systems but the major weakness is data redundancy and inconsistency. By data redundancy, I mean duplication of data. There are no better methods to validate insertion of duplicate data in file systems. Data redundancy can also increase the chance for errors.






7 0
3 years ago
A(n) ____ circular reference occurs when a formula in a cell refers to another cell or cells that include a formula that refers
weeeeeb [17]
Indirect is the correct answer. 
8 0
3 years ago
Contrast the performance of the three techniques for allocating disk blocks (contiguous, linked, and indexed) for both sequentia
Pie
The allocation methods define how the files are stored in the disk blocks.
There are three main disk space or file allocation methods:
1.Contiguous Allocation-in this scheme,each file occupies a set of blocks on the disk. For example if a file requires x blocks and is given a block y as the starting location,then the blocks assigned to the file be :x,y+1,y+2,......y+x-1.
This means that given the starting block address and the length of the file(in terms of blocks required) we can determine the blocks occupied by the file.
Advantages
-both the sequential and direct accesses are supported
-this is extremely fast since the number of seeks are minimal because of contiguous allocation of file blocks.
2.linked allocation-in this scheme,each file linked list of disk blocks which need not  be contiguous disk blocks can be scattered anywhere on the disk.
Advantages
it is very flexible in terms of file size.file size can be increased easily since the system does not have to look for a contiguous chunk 
of memory.
this method does not suffer from external fragmentation and it makes it relatively better in terms of memory utilization.
3.Indexed Allocation-in this scheme,a special block known as the index block contains the pointers to all the blocks occupied by a file.Each file has its own index block.the entry in the index block contains the disk address of the block
Advantages
it supports direct access to the blocks occupied by the file and therefore provides fast access to the file blocks
it overcomes the problem of external fragmentation.
3 0
3 years ago
Read 2 more answers
Which activity should be part of a long-term plan to positively affect your
STatiana [176]
D that is the answer but I need 20 words to send this text
5 0
2 years ago
The Occupational Outlook Handbook is published by the Bureau of Labor Statistics.
vlabodo [156]
A. True
It was written in 1948 by the Bureau of Labor Statistics
7 0
3 years ago
Read 2 more answers
Other questions:
  • To instruct Oracle11 g to sort data in ascending order, enter ____ after the column name in the ORDER BY clause.
    15·2 answers
  • A review of the sales, costs, and profit projections for anew product to find out whether these factors satisfy the company'sobj
    15·1 answer
  • A major difference between digital librarians and traditional librarians is that traditional librarians rarely work with people.
    15·2 answers
  • Input parts of computer
    7·2 answers
  • If you are inserting an address block with the Address Block dialog box and the fields do not connect automatically, what can yo
    6·2 answers
  • 1. Create an anonymous block that will count the number of students whose gr_t1 grade is higher than the average on gr_t1 and di
    13·1 answer
  • Choose all the answers that apply.
    14·2 answers
  • Conceptos importantes de red de computadoras
    11·1 answer
  • Which statement describes the relationship between science and technology?
    13·2 answers
  • Module 1 and 2 Coding Guided Notes Fill in your answers to each response as you read through the lesson pages in the coding cour
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!