Pattern Program Logic In Java