Time limit exceed using java

i am getting time limit exceeded error when i code this probiem in java but if i switch to c and write absolutely same code my code is accepted.Can you tell me where the problem appear in java

QUESTION:
http://codeforces.com/problemset/problem/302/A

MY ANSWER: