string building & output in java