Java Reference
In-Depth Information
•
On line 8,
System.out println
should be
System.out.println
.
•
On line 8,
cannot ";
should be
cannot ")
.
•
On line 9, the phrase
"errors"
cannot appear inside a
String. 'errors'
would
work.
•
On line 11, there should be a closing
}
brace.
27.
(a) Syntax error: The program would not compile because its class name
(
Demonstration
) would not match its file name (
Example.java
).
(b) Different program output: The program would not run because Java would be
unable to find the
main
method.
(c) Different program output: There would now be a blank line between the two
printed messages.
(d) Syntax error: The program would not compile because the
main
method would
be calling a method (
displayRule
) that no longer existed.
(e) No effect: The program would still compile successfully and produce the same
output.
(f) Different program output: The output would now have no line break between
"The first rule"
and
"of Java Club is,"
in its output.
28.
// This program displays a message about formatting programs.
public class GiveAdvice {
public static void main(String[] args) {
System.out.println("Programs can be easy or");
System.out.println("difficult to read, depending");
System.out.println("upon their format.");
System.out.println();
System.out.println("Everyone, including yourself,");
System.out.println("will be happier if you choose");
System.out.println("to format your programs.");
}
}
29.
// This program shows messages about formatting.
public class Messy {
public static void main(String[] args) {
message();
System.out.println();
message();
}
public static void message() {
System.out.println("I really wish that");
System.out.println("I had formatted my source");
System.out.println("code correctly!");
}
}
Search WWH ::
Custom Search