Find median of Java Array and List values using 2 ways What is Median? Median is mid value of particular data set. This data set must be sorted. In simple word, Median is mid value of sorted data. Median will be middle, if total number of elements is odd or average of middle elements when total number of elements is even. Example : When total number of elements are odd 1, 2, 3, 4, 5, 6, 7 Median will be : 4 2, 3, 5, 7, 8 Median will be : 5 When total number of elements are even 1, 2, 3, 4 Median will be : (2+3) / 2 : 2.5 2, 4, 6, 8, 10, 20, 25, 30 Median will be : (8+10) / 2 : 9 So the formula become for our code : For odd elements : Median = (Total length / 2) For even elements : Median = (Total length / 2) + (Total length / 2 - 1) / 2 So lets jump on code. We will take elements form user. Method 1 : Using code logic In this approach, we does not use any library function for find median. Example 1 : Find median from Java array import java.util.Arrays; import java.util.Scanner; pu...
Welcome To Programming Tutorial. Here i share about Java Programming stuff. I share Java stuff with simple examples.