// CopyInt8.java -- read comma separated ints from the standard input stream import java.util.Scanner; /* * System.in (java.io.InputStream) is the standard input * System.out (java.io.PrintStream) is the standard output */ /* * Note the try-resource statement for closing the stream. Also * note the use of regular expressions. */ /* * Note the example of OO method chaining (from SmallTalk, as are many OO * idoms). Since it only makes sense for mutable objects, it is not * something to emulate. */ public final class CopyInt8 { public static void main (final String[] args) { try (final Scanner stdin = new Scanner(System.in, "US-ASCII").useDelimiter("[\\s,]+")) { // Read from the standard input stream while (stdin.hasNextInt()) { final int n = stdin.nextInt(); // get the next int from input System.out.println(n); // write the int to output } } } }