1.

/**
* Angewandte Mathematik, SS11
* Problem: 10107 - What is the Median?
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=13&page=show_problem&problem=1048
*
* @author Markus Schöllner
* @author Andreas Maier
* @version 1.0, 06/12/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.912
*/


import java.util.*;
import java.util.Scanner;


public class Main {

public static void main(String[] args) {
Scanner input = new Scanner(System.in);
ArrayList<Integer> numbers = new ArrayList<Integer>();
int temp;


numbers.add(input.nextInt());
System.out.println(numbers.get(0));

while(input.hasNext()){
temp = input.nextInt();

//neue Nummer wird direkt an der richtigen Stell einsortiert
for(int c = 0; c < numbers.size(); c++) {
if(temp < numbers.get(c)) {
numbers.add(c, temp);
break;
}
if(c == numbers.size()-1){
numbers.add(temp);
break;
}
}

if(numbers.size()%2 != 0) System.out.println(numbers.get(numbers.size()/2));
else {
System.out.println( ((numbers.get(numbers.size()/2-1)) + (numbers.get(numbers.size()/2)))/2 );
}
}
}
}
--------------------------------



1.

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

/**
 * Problem #10107 - What Is The Median -
 * http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=13&page=show_problem&problem=1048
 *
 * Status : Accepted
 * Runtime: 2.664
 */

/**
 * @author Mariya Vlaseva
 *
 */
public class Main {


    public static void main(String... args) {
        Scanner sc = new Scanner(System.in);
        ArrayList<Integer> numbers = new ArrayList<Integer>();
       
        while(sc.hasNext()) {
            numbers.add(sc.nextInt());
            Collections.sort(numbers);   
            System.out.println(median(numbers));
        }
    }
   
    public static int median(ArrayList<Integer> m) {
        int middle = m.size()/2;  // subscript of middle element
        if (m.size()%2 == 1) {
            // Odd number of elements -- return the middle one.
            return m.get(middle);
        } else {
           // Even number -- return average of middle two
           // Must cast the numbers to double before dividing.
           return (m.get(middle-1) + m.get(middle) )/ 2;
        }
    }//end method median

}