Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: How to get Median/Middle value in an array?

1. ## How to get Median/Middle value in an array?

So first of all we use textpad in our java course (idk why) and the Easy.In method for our input.

anyway I have this assignment and we're ask to make a program that input 1) how many numbers were input 2) the largest value 3)smallest value 4) average value and 5) middle/median value. I manage to figure out the code for the other except the median value. So i'm here asking for help!

here's my code

```class project2
{
public static void main(String[] args)
{
System.out.println("How many numbers you want to input");
int maxItems = EasyIn.getInt();

int[] numbers = new int[maxItems];

for(int i = 0; i < maxItems; i++)
{
System.out.println("Enter the value of number " + (i+1));
numbers[i] = EasyIn.getInt();
}

System.out.println("The total count of numbers you inputed is " +maxItems);

findlargest(numbers);
findsmallest(numbers);
findaverage(numbers);
findmiddle(numbers);

}

public static void findlargest(int[]nos)
{
int largest = 0;

for(int i = 0; i < nos.length; i++)
{
if(nos[i] > largest)

largest = nos[i];
}
System.out.println(" ");
System.out.println("The largest value is " +largest);
}

public static void findsmallest(int[]nos)
{
int smallest = nos[0];

for(int i = 0; i < nos.length; i++)
{
if(nos[i] < smallest)

smallest = nos[i];
}
System.out.println(" ");
System.out.println("The smallest value is " +smallest);
}

public static void findaverage(int[]nos)
{
double total = 0;
double average;

for(int i = 0; i < nos.length; i++)
{
total += nos[i];
}
average = total / nos.length;
System.out.println(" ");
System.out.println("The average value is " +average);
}

public static void findmiddle(int[]nos)

{
}
}```