Package stdlib

Class StdArrayIO

java.lang.Object
stdlib.StdArrayIO

public class StdArrayIO extends Object
This class provides methods for reading in 1D and 2D arrays from standard input and printing out to standard output.

For additional documentation, see Section 2.2 of Computer Science: An Interdisciplinary Approach by Robert Sedgewick and Kevin Wayne.

Author:
Robert Sedgewick, Kevin Wayne
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    main(String[] args)
    Unit tests StdArrayIO.
    static void
    print(boolean[] a)
    Prints a 1D array of booleans to standard output.
    static void
    print(boolean[][] a)
    Prints a 2D array of booleans to standard output.
    static void
    print(double[] a)
    Prints an array of doubles to standard output.
    static void
    print(double[][] a)
    Prints the 2D array of doubles to standard output.
    static void
    print(int[] a)
    Prints an array of integers to standard output.
    static void
    print(int[][] a)
    Print a 2D array of integers to standard output.
    static boolean[]
    Reads a 1D array of booleans from standard input and returns it.
    static boolean[][]
    Reads a 2D array of booleans from standard input and returns it.
    static double[]
    Reads a 1D array of doubles from standard input and returns it.
    static double[][]
    Reads a 2D array of doubles from standard input and returns it.
    static int[]
    Reads a 1D array of integers from standard input and returns it.
    static int[][]
    Reads a 2D array of integers from standard input and returns it.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • readDouble1D

      public static double[] readDouble1D()
      Reads a 1D array of doubles from standard input and returns it.
      Returns:
      the 1D array of doubles
    • print

      public static void print(double[] a)
      Prints an array of doubles to standard output.
      Parameters:
      a - the 1D array of doubles
    • readDouble2D

      public static double[][] readDouble2D()
      Reads a 2D array of doubles from standard input and returns it.
      Returns:
      the 2D array of doubles
    • print

      public static void print(double[][] a)
      Prints the 2D array of doubles to standard output.
      Parameters:
      a - the 2D array of doubles
    • readInt1D

      public static int[] readInt1D()
      Reads a 1D array of integers from standard input and returns it.
      Returns:
      the 1D array of integers
    • print

      public static void print(int[] a)
      Prints an array of integers to standard output.
      Parameters:
      a - the 1D array of integers
    • readInt2D

      public static int[][] readInt2D()
      Reads a 2D array of integers from standard input and returns it.
      Returns:
      the 2D array of integers
    • print

      public static void print(int[][] a)
      Print a 2D array of integers to standard output.
      Parameters:
      a - the 2D array of integers
    • readBoolean1D

      public static boolean[] readBoolean1D()
      Reads a 1D array of booleans from standard input and returns it.
      Returns:
      the 1D array of booleans
    • print

      public static void print(boolean[] a)
      Prints a 1D array of booleans to standard output.
      Parameters:
      a - the 1D array of booleans
    • readBoolean2D

      public static boolean[][] readBoolean2D()
      Reads a 2D array of booleans from standard input and returns it.
      Returns:
      the 2D array of booleans
    • print

      public static void print(boolean[][] a)
      Prints a 2D array of booleans to standard output.
      Parameters:
      a - the 2D array of booleans
    • main

      public static void main(String[] args)
      Unit tests StdArrayIO.
      Parameters:
      args - the command-line arguments