Java: Logic and Arithmetic