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. EX 2.5. What is the output produced by the following statement? Explain.
Background image of page 1

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

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

This note was uploaded on 07/26/2011 for the course COP 2551 taught by Professor Roggio,r during the Summer '08 term at UNF.

Page1 / 5

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

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online