Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Imagine that we have the following list of words: There are 5 words in this list

ID: 3875070 • Letter: I

Question

Imagine that we have the following list of words:

There are 5 words in this list, with the middle word being 'on'. When the length of the list is an odd number, there is exactly one middle word. If the length is even, on the other hand, then there are two middle words. For example, in the case of:

the two middle words are 'sheep' and 'have'.

Your task is to write a function middle_words(word_list) that returns the middle word(s) from the non-empty list-of-strings word_list. If the length of word_list is an odd number, you should return a list containing the single middle word; and if the length of word_list is an even number, you should return a list containing the two middle words, in the same order as they occurred in the word_list. For example:

Explanation / Answer

import java.io.*;
public class stmat
{
public static void main(String []args)throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int i,n,mid;
n=0;
System.out.println("Enter the size of the array "); //accepting the size of the array
n=Integer.parseInt(br.readLine());
mid=n/2;
String a[]=new String[n];
System.out.println("Enter the elements in the array"); //accepting the string
for(i=0;i<n;i++)
a[i]=br.readLine();
if(n%2==0) //checking for odd or even
System.out.println(a[mid-1]+" "+a[mid]); //displaying the result.
else
System.out.println(a[mid]);
  
}
}