algorith with java