Chapter 2 Introduction (Web design software) to Java Applications 63 1

Chapter 2 Introduction to Java Applications 63 1 // Fig. 2.3: Welcome2.java 2 // Printing a line of text with multiple statements. 3 4 public class Welcome2 { 5 6 // main method begins execution of Java application 7 public static void main( String args[] ) 8 { 9 System.out.print( “Welcome to ” ); 10 System.out.println( “Java Programming!” ); 11 12 } // end method main 13 14 } // end class Welcome2 Welcome to Java Programming Fig. 2.3Printing a line of text with multiple statements. Fig. 2. display one line of text in the command window. The first statement uses System.out s method print to display a string. The difference between printand printlnis that, after displaying its argument, print does not position the output cursor at the beginning of the next line in the command window; the next character the program displays in the command window will appear immediately after the last character that print displays. Thus, line 10 positions the first character in its argument, J, immediately after the last character that line 9 displays (the space character at the end of the string on line 9). Each printor printlnstatement resumes displaying characters from where the last print or printlnstatement stopped displaying characters. 2.3.2 Displaying Multiple Lines of Text with a Single Statement A single statement can display multiple lines by using newline characters. Newline characters are special characters that indicate to System.out s print and println methods when they should position the output cursor to the beginning of the next line in the command window. Figure 2.4 outputs four lines of text, using newline characters to determine when to begin each new line. Most of the program is identical to those of Fig. 2.1 and Fig. 2.3, so we discuss only the changes here. Line 2, // Printing multiple lines of text with a single statement. is a single-line comment stating the purpose of this program. Line 4 begins the definition of class Welcome3. Line 9, System.out.println( “WelcomentonJavanProgramming!” ); displays four separate lines of text in the command window. Normally, the characters in a string are displayed exactly as they appear in the double quotes. Notice, however, that the Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/2/01
Note: In case you are looking for affordable and reliable webhost to host and run your business application check Vision ftp web hosting services

Leave a Reply