unary operator problem solving in java