CHAPTER 2 - Java Software Solutions 4e Lewis and Loftus...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Java Software Solutions, 4e Lewis and Loftus Chapter 2 Exercise Solutions 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. 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. 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. 2.4. What output is produced by the following statement? Explain.
Image of page 1

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

View Full Document Right Arrow Icon
Java Software Solutions, 4e Lewis and Loftus 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 sting
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern