Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Java Programming 8th edition chapter 9 #2-part b(MeanMedian2). How do I fix the following? There is no type conversion for median in the second

In Java Programming 8th edition chapter 9 #2-part b(MeanMedian2). How do I fix the following?

There is no type conversion for median in the second program.

You can use (double) casting operator at the beginning of the right hand side formula.

This is the program I used, it seems to work but I dont understand where exactly I am supposed to put the double.

import java.util.Arrays;

import java.util.Scanner;

public class MeanMedian2

{

public static void main(String[] args)

{

int list[] = new int[20];

int t,x,n=0;

double mean=0, median=0;

Scanner sc=new Scanner(System.in);

System.out.println("Please enter max of 20 numbers or NAN to exit");

try

{

for(int i=0;i<20;i++)

{

x=sc.nextInt();

list[i]=x;

n++;

}

}

catch(Exception e)

{

System.out.println("Thanks for the input");

}

for(int i=0;i

{

mean = mean+list[i];

}

mean = mean/n;

{

for(int i=0;i

{

for(int j=i+1;j

{

if(list[i]>list[j])

{

t=list[i];

list[i]=list[j];

list[j]=t;

}

}

}

int m=n/2;

if(n%2==0)

{

median=(list[m]+list[m-1])/2;

}

else median=list[m];

System.out.println("Mean is "+mean +" Median is "+median);

for(int i=0;i

{

System.out.println(list[i]);

}

}

}

}

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

Spatio Temporal Database Management International Workshop Stdbm 99 Edinburgh Scotland September 10 11 1999 Proceedings Lncs 1678

Authors: Michael H. Bohlen ,Christian S. Jensen ,Michel O. Scholl

1999th Edition

3540664017, 978-3540664017

More Books

Students also viewed these Databases questions

Question

How does selection differ from recruitment ?

Answered: 1 week ago