Logic Heart interview question

Java