Basic Input and Output in Java
Using the JMUConsole Class |
Prof. David Bernstein
|
Computer Science Department |
bernstdh@jmu.edu |
JMUConsole
(you'll have to
download the .class
file
into the directory containing your source code)
"
character is used to denote a
String
literal. So, how can one include
a "
character in a String
?
\"
(which is a single char
)"She said \"None for me, thanks.\" and left."
\
character it
too must be escaped (i.e., \\
)\n
for newline\r
for carriage return\t
for tabString
variablesString
literalsString
literal to a String
variable+
can be used to concatenate
its two operands (one of which must be a String
)
and evaluates to
a String
JMUConsole
JMUConsole.open()
exactly once, before you can use
the JMUConsole
for input or output
JMUConsole.close()
after you are done (i.e., just before the program terminates)
JMUConsole.print(value)
prints the value (whatever type it is)JMUConsole.println(value)
prints the
value followed by a line separatorJMUConsole.printf(Format, value[, value]...)
prints one or more values formatted according to
the Format stringString
literalsboolean
char
String
nextDouble()
, nextInt()
double
value or int
valuenextLine()
String
(i.e., what the user has typed up to the next line
delimiter)next()
String
(i.e., what the user has typed up to the next token
delimiter)System.out.print()
,
System.out.printf()
, etc... JMUConsole.print()
, JMUConsole.printf()
,
etc... work the same way but don't use the out
object which you don't yet understand
Scanner
class
and methods like nextInt()
,
nextDouble()
, etc... JMUConsole.nextInt()
,
JMUConsole.nextDouble()
,
etc... work the same way but don't require the use of
new
and an assignment to an object that
you don't yet understand (but does require that you call
open()
instead)readDouble()
, readInt()
double
value or int
value and "consume" the newline characterreadLine()
nextLine()