troubleshooting Question

How to locate and display the Median value of an Array

Avatar of Mkelliny
Mkelliny asked on
Java
20 Comments2 Solutions330 ViewsLast Modified:
I need to create a program that has 9 values in an array they must be sorted in ascending order then displayed. The program is to then find the median value and display it as well. I think that I almost have it, but I am getting a lot of errors.  Any help is extremely appreciated.
import java.util.Collections;
import java.util.Arrays;
public class Median
 {

	public static void main(String[] args)

	{
	
	     	int[] arrayNum = new int[] {600, 59, 754, 169, 420, 699, 1000, 800, 999};
			int numSort = arrayNum.length - 1;
			for(a = 0; a < arrayNum.length - 1; ++a)
			{
				for(b = 0; b < numSort; ++b)
				{
					if(arrayNum[b] > arrayNum[b + 1])
					{
						temp = arrayNum[b];
						arrayNum[b] = arrayNum[b + 1];
						arrayNum[b + 1] = temp;
						System.out.println("Numbers in the array = " + arrayNum[b]);
					}
				}
			
			--numSort;
			}
	}
			
	public static double median(double[] m)
	{
    int middle = m.length/2;  
    if (m.length%2 == 1) {
        
        return m[middle];
    } else 
	 {
       
       return (m[middle-1] + m[middle]) / 2.0;
		 System.out.println("Median number in the array = " + middle[b]);
    }
	}
}
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 20 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 20 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros