From 62d4d703a8c5c1ec7443e3d7ac120d8a8535f6cb Mon Sep 17 00:00:00 2001 From: Deathsbreed Date: Thu, 10 Apr 2014 17:24:08 -0500 Subject: [PATCH] Fixed median calculation for even array length. Verbose needs fix. --- src/MMMCalc.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/MMMCalc.java b/src/MMMCalc.java index a4d5128..3d9f040 100644 --- a/src/MMMCalc.java +++ b/src/MMMCalc.java @@ -130,8 +130,15 @@ public class MMMCalc { private static void calcMedian() { int midVar = numArray.length / 2; + boolean even; - median = numArray[midVar]; + if(numArray.length % 2 == 0) { + median = (numArray[midVar] + numArray[midVar-1]) / 2; + even = true; + } else { + median = numArray[midVar]; + even = false; + } System.out.println("Median: " + median);