Java demonstration console algorithm