OUTPUT [FILE (\"fileName\" | fileNameStringvariable)] [APPEND] (\"format string\" | formatStringVariable) {number}"

This command writes a string with a number of embedded numbers to the Output Window, or optionally writes the string and embedded numbers to the named file. The output string is not terminated with a newline unless the format string ends with a newline character. The newline character is '\n'.

If present, keywords must be in the order shown, i.e., file followed by the file name followed by the optional append keyword.

If the file keyword is present, it must be followed by a filename in quotes or by a String Variable containing a filename. The filename may be the complete path name or a relative path. A relative path will be relative to the current user directory (the directory containing the statistics101.jar file).

If the append keyword is present along with the file keyword, the OUTPUT command will append the string to the named file, if it exists, or will create a file by that name and write the string to the file. The default behavior in the absence of the append keyword, is to create the file if it doesn't exist and write the string to it, or if the file already exists, to overwrite it with the string. If the file keyword is absent, append will be ignored.

The argument(s), number, is a variable or a constant. Only the first element of any number argument will be used.

The argument formatString contains zero or more format specifications. The formatString must be enclosed in double-quotes. There should be one format specification in the formatString for each number. If there are more numbers than format specifications, the extra numbers will be ignored. If there are fewer numbers than format specifications, the extra format specifications will be treated simply as text and sent to the output unchanged.

The format specification can use any of the format codes (f, e, g, b, or c) that are valid for the WRITE command. There is one difference between the behavior of the format codes for OUTPUT from that of WRITE: When used for the OUTPUT command, the formats do not generate delimiters such as space, comma, or tab. Not automatically generating such delimiters gives you more control over the formatting. You put your formatting characters in the format string wherever you want them.

Here is the list of special formatting characters you can use in the format string:

  • Tab: \t

  • Carriage Return: \r

  • Newline: \n

  • Quote: \"

The general format specification is:



  • % introduces the format specification.

  • [...] means "optional" (0 or one occurrences).

  • width is a number that specifies the minimum width, in characters, that the number is allowed to have. The width includes the decimal point, any numbers before and after the decimal point, and the exponent, if any. For example, this number, 123.45, has width 6. This number, 1.234E02, has width 8. Note that the specified width is a minimum; therefore, if the number cannot be fit within the specified width, it will be allowed as much room as needed. If the width is greater than needed to fit the number, the number will be followed by spaces to fill the width.

  • precision is a number that specifies the maximum number of significant digits or the maximum number of decimal places of this specification's output. For example, this number, 123.45, has a precision of 2. The number 1.234E02 has a precision of 4. That's because the precision for a number in scientific notation refers to the number of significant digits. The precision for a fixed point number refers to the number of digits after the decimal point.

  • code is one of 'F', 'E', 'G', 'B', or 'C' either upper or lower case. If code is absent, it is assumed to be 'G'.

    • F specifies fixed point output. The precision specifies the number of digits after the decimal point.

    • E specifies Scientific Notation output. precision specifies the number of significant digits.

    • G specifies "General" notation. This will be either fixed point or Scientific Notation depending on the number.

    • B is same as G.

    • C is the same as G.

The codes may be entered in either upper or lower case. No distinction is made by Statistics101.


The simplest OUTPUT command, with only a string argument, would be equivalent to the PRINT command except that the OUTPUT command does not automatically terminate with a newline. Therefore, multiple OUTPUT commands would print successively to the same line:

OUTPUT "First output,"
OUTPUT " second output,"
OUTPUT " third output\n" 'This \n is a newline.

The result is this:

First output, second output, third output

Here's an example embedding two constants into a single line:

COPY 1,100 a
STDEV a sd
MEAN a avg
OUTPUT "Standard Deviation is %5.2e and the Mean is %4\n" sd avg

The above program produces this one line output:

Standard Deviation is 2.9E01 and the Mean is 5E01

The following program produces the same result using two output commands:

COPY 1,100 a
STDEV a sd
MEAN a avg
OUTPUT "Standard Deviation is %5.2e" sd
OUTPUT " and the Mean is %4\n" avg


Standard Deviation is 2.9E01 and the Mean is 5E01

The numbers are inserted into the format string, in order, replacing the format specifications. Here's an example showing the use of tabs to format the output:

COPY 1,100 population
SAMPLE 15 population sample1
SAMPLE 15 population sample2
SAMPLE 15 population sample3
MEAN population mean
MEAN sample1 mean1
MEAN sample2 mean2
MEAN sample3 mean3
OUTPUT "Population mean: %3.2f\n" mean
OUTPUT "Sample 1 mean:\t%3.2f\n" mean1
OUTPUT "Sample 2 mean:\t%3.2f\n" mean2
OUTPUT "Sample 3 mean:\t%3.2f\n" mean3

Result of one run:

Population mean: 50.5
Sample 1 mean:  59
Sample 2 mean:  49.8
Sample 3 mean:  56.6

An example containing quotes:

OUTPUT "He said, \"I can do it.\""

produces the following output:

He said, "I can do it."