Algorithm implement by Java