#brainfuck, 33 bytes
,>,[<[->->+<<]>[[-]>.<]>[-]<<,>,]
Compared to Java, this is very compact, however, I'm afraid of brainfuck-golfer answerer. And feel free to mention if there's a bug. Assuming EOF is 0, input doesn't contain invalid input, the cell is initially zero, and the cell value range is finite and cyclic. No other assumption is present.
Explanation:
Memory Cell Map
+---------+---------+-----------------+
|1st input|2nd input|copy of 1st input|
+---------+---------+-----------------+
Instruction
,>, read two instruction at once | first to first cell |
second to second cell
[ Until the input is EOF
< look at first cell
[->->+<<] move the first cell to additional cells while
subtracting the second cell with this at same
time
>[ if the second cell is nonzero (it means that first cell and
the second cell is the same)
[-]>.< Print the copied first input
]
>[-] clear the first input to prevent it polluting next input
<<,>, continue with next two input
]