Java Reference
In-Depth Information
What would happen if each of the following changes was made to the Example program? For example, would there
be no effect, a syntax error, or a different program output? Treat each change independently of the others.
a. Change line 1 to: public class Demonstration
b. Change line 9 to: public static void MAIN(String[] args) {
c. Insert a new line after line 11 that reads: System.out.println();
d. Change line 2 to: public static void printMessage() {
e. Change line 2 to: public static void showMessage() { and change lines 11 and 12 to: showMessage();
f. Replace lines 3-4 with: System.out.println("The first rule of Java Club is,");
28. The following program is legal under Java's syntax rules, but it is difficult to read because of its layout and lack of
comments. Reformat it using the rules given in this chapter, and add a comment header at the top of the program.
1 public
2 class GiveAdvice{ public static
3 void main (String[ ]args){ System.out.println (
4
5 "Programs can be easy or"); System.out.println(
6 "difficult to read, depending"
7 ); System.out.println("upon their format.")
8 ;System.out.println();System.out.println(
9 "Everyone, including yourself,");
10 System.out.println
11 ("will be happier if you choose");
12 System.out.println("to format your programs."
13 ); }
14 }
29. The following program is legal under Java's syntax rules, but it is difficult to read because of its layout and lack of
comments. Reformat it using the rules given in this chapter, and add a comment header at the top of the program.
1 public
2 class Messy{ public
3 static void main(String[]args){message ()
4 ;System.out.println() ; message ( );} public static void
5 message() { System.out.println(
6 "I really wish that"
7 );System.out.println
8 ("I had formatted my source")
9 ;System.out.println("code correctly!");}}
 
Search WWH ::




Custom Search