Class stdio
java.lang.Object
|
+--stdio
- public class stdio
- extends java.lang.Object
stdio defines static methods for using typed input from the console window. This
class includes two methods for getting a line of input, two methods for
handling (i.e. parsing) typed-in numbers, and a simple rounding method so that
System.out.println won't print "0.33333333333333333" when you want to see "0.33".
Known uses: I have used this class successfully as a way to let my students
produce command-line applications that they can run in a MS-DOS command line window.
This lets them get started without first having to climb the learning curve for
Java GUI programming (AWT and Swing).
Hints for use: Put stdio.java and stdio.class into your project folder and
then use stdio in your project as you would use any other class.
Version 1.0
|
Constructor Summary |
stdio()
|
|
Method Summary |
static java.lang.String |
getLine()
returns line of typed input as a String. |
static java.lang.String[] |
getLineTokens()
returns line of typed input as an array of Strings. |
static java.lang.Double |
parseDouble(java.lang.String s)
attempts to parse input string into a Double. |
static java.lang.Integer |
parseInteger(java.lang.String s)
attempts to parse input string into an Integer. |
static double |
round2(double x)
rounds a double to 2 or fewer digits to the right of the decimal point |
| Methods inherited from class java.lang.Object |
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
stdio
public stdio()
getLine
public static java.lang.String getLine()
- returns line of typed input as a String. If the line is empty, returns a zero-length string.
getLineTokens
public static java.lang.String[] getLineTokens()
- returns line of typed input as an array of Strings. Each String in the array contains
one word of the input. If the line is empty, returns null.
parseDouble
public static java.lang.Double parseDouble(java.lang.String s)
- attempts to parse input string into a Double. Returns null if it can't.
parseInteger
public static java.lang.Integer parseInteger(java.lang.String s)
- attempts to parse input string into an Integer. Returns null if it can't.
round2
public static double round2(double x)
- rounds a double to 2 or fewer digits to the right of the decimal point
Generated by BlueJ