Java scanning and printing