I am not sure if I understand your do-while loop correctly. The loop is "repeated" only if the the first read int i = in.nextInt; returned a value unequal 0.