{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Chap02 EX Solutions

Chap02 EX Solutions - Java Software Solutions 6th Edition...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Java Software Solutions, 6 th Edition Exercise Solutions, Ch. 2 Chapter 2 Exercise Solutions EX 2.1. Explain the following programming statement in terms of objects and the services they provide. System.out.println ("I gotta be me!"); The System.out object has a println method which accepts a string, enclosed in parentheses and quotation marks, which it displays on the monitor. EX 2.2. What output is produced by the following code fragment? Explain. System.out.print ("Here we go!"); System.out.println ("12345"); System.out.print ("Test this if you are not sure."); System.out.print ("Another."); System.out.println (); System.out.println ("All done."); The output produced is: Here we go!12345 Test this if you are not sure.Another. All done. After printing its data, the println method moves to the next line of output, whereas the print method does not. A println statement with no data has the effect of moving down to the next line. EX 2.3. What is wrong with the following program statement? How can it be fixed? System.out.println ("To be or not to be, that is the question."); The string to be printed is not all on one line. The problem can be fixed by using the string concatenation operator (+) or by using a print statement for part of the string and a println statement for the remainder of the string. EX 2.4. What output is produced by the following statement? Explain. System.out.println ("50 plus 25 is " + 50 + 25); The output produced is: 50 plus 25 is 5025 First the string “50 plus 25” is concatenated with the integer 50; since one of the operands associated with the “+” operator is a string, the result is a string. Then the string “50 plus 25 is 50” is concatenated with the integer 25, with similar results.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}