java progr. with two algos