Write a statement to print the words "The parameter is ", followed
by the value of the variable theParameter
.
System.out.println ("The parameter is \"" + theParameter + "\".");
println
.theParameter
in quotation marks."theParameter"
,
that's exactly what you'll see: the
letter "t", then "h", then "e", then
"P", then "a", etc. The assignment
was to print out the value of the variable
theParameter
, not its name.
System.out.println(...)
is a statement,
and therefore must end with a semicolon.System.out.
println("The parameter is \"" + theParameter + "\".");you're really saying
this.println(...)
However, this
is an instance of the QuizClass
class, which doesn't have a
println
method, so the statement won't compile.
System.out
is a predefined object of a class which
does have a method named println
.
println
method is defined to take in one String
parameter. It cannot take two or three, so if you have several strings
to print on the same line, the usual tactic is to concatenate
them using +
or concat(...)
.
System.out.println ("The parameter is "" + theParameter + "".");the Java compiler will think the first string is
"The parameter is "
,
followed immediately (with no operators in between) by the string
" + theParameter + "
,
followed immediately again by the string
"."
.
It will probably produce the error message ") or , expected", because when
one string argument to a method is over, it expects the next character to
be either a comma (before the next argument) or a right parenthesis
(closing the argument list).