• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 4 out of 93 pages
Summary

Summary Simplify Learning in with [Java Foundations,Lewis,3e] Study Guide

Document preview thumbnail
Preview 4 out of 93 pages

Take Control of Your Academic Journey with [Java Foundations,Lewis,3e] Solutions Manual! Don't let challenging exercises hold you back from achieving your goals. Our Solutions Manual for [Java Foundations,Lewis,3e] provides a roadmap to success. By following the step-by-step solutions, you'll not only master the material but also develop problem-solving skills that will benefit you throughout your academic and professional life. Empower yourself with the tools to conquer any obstacle.

Content preview

Chapter 1 Exercise Solutions
EX 1.1. Give examples of the two types of Java comments and explain the
differences between them.
One kind of comment begins with a double slash (//) and continues to the end of the
line. A second kind of comment begins following an initiating slash-asterisk (/*) and
terminates immediately preceding a terminating asterisk-slash (*/). The second type of
comment can span multiple lines.

EX 1.2. Which of the following are not valid Java identifiers? Why?
a. Factorial
Valid
b. anExtremelyLongIdentifierIfYouAskMe
Valid
c. 2ndLevel
Invalid because it begins with a digit
d. level2
Valid
e. MAX_SIZE
Valid
f. highest$
Valid
g. hook&ladder
Invalid because it contains an ampersand (&)

EX 1.3. Why are the following valid Java identifiers not considered good identi-
fiers?
a. q
The identifier q is a meaningless name.

b. totVal
The identifier totalValue would be more meaningful than the abbreviation.

c. theNextValueInTheList
Unnecessarily lengthy; nextValue would serve as well.

EX 1.4. Java is case sensitive. What does that mean?
Uppercase characters are considered to be distinct from lowercase letters. Therefore
the identifier HELLO is distinct from Hello which is distinct from hello.

,EX 1.5. What do we mean when we say that the English language is ambiguous?
Give two examples of English ambiguity (other than the example used in
this chapter) and explain the ambiguity. Why is ambiguity a problem for
programming languages?
Something is ambiguous if it has two or more possible meanings. For example, the
statement, “Mary is the nicest teaching assistant who has helped me all day long” might
mean 1) of all the teaching assistants who have helped me today, Mary is the nicest, or
2) of those teaching assistants who have helped me for an entire day, Mary is the
nicest. As another example, the statement, “Bananas help those who help themselves”
might mean 1) bananas are good for those who attend to their own welfare or 2)
bananas are good for those who eat as many bananas as they please. If a
programming language statement could be interpreted in two or more ways, it would be
impossible to predict with certainty how it would be interpreted and what result would
be produced.

EX 1.6. Categorize each of the following situations as a compile-time error, run-
time error, or logical error.
a. multiplying two numbers when you meant to add them
A logical error
b. dividing by zero
A run-time error
c. forgetting a semicolon at the end of a programming statement
A compile-time error
d. spelling a word wrong in the output
A logical error
e. producing inaccurate results
A logical error
f. typing a { when you should have typed (

A compile-time error

, Chapter 2 Exercise Solutions
EX 1.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 character string as a
parameter. The service the println method provides is to display the string on the
monitor.

EX 1.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 1.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 splitting the
long string into two and using the string concatenation operator (+) to reconstruct it, or
by using a print statement for part of the string and a println statement for the
remainder of the string.

EX 1.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 ” is concatenated with the integer 50; since one of the
operands is a string, the result is a string. Then the string “50 plus 25 is 50” is
concatenated with the integer 25, producing the final result.

, EX 1.5. What is the output produced by the following statement? Explain.
System.out.println ("He thrusts his fists\n\tagainst"
+
" the post\nand still insists\n\the sees
the \"ghost\"");
The output produced is:
He thrusts his fists
against the post
and still insists
he sees the "ghost"
Escape characters are used to go to the beginning of new lines (\n), to tab (\t), and to
print quotation marks (\").

EX 1.6. What value is contained in the integer variable size after the following
statements are executed?
size = 18;
size = size + 12;
size = size * 2;
size = size / 4;
The final value stored in size is 15.

EX 1.7. What value is contained in the floating point variable depth after the
following statements are executed?
depth = 2.4;
depth = 20 – depth * 4;
depth = depth / 5;
The final value stored in depth is 2.08.

EX 1.8. What value is contained in the integer variable length after the following
statements are executed?
length = 5;
length *= 2;
length *= length;
length /= 100;
The final value stored in length is 1.

EX 1.9. Write four different program statements that increment the value of an
integer variable total.
total = total + 1;

Connected book
 image
John Lewis, Peter DePasquale, Joe Chase Java Foundations
Publisher: 2013 ISBN: 9780133437355 Edition: Unknown

Document information

Summarized whole book?
Yes
Uploaded on
July 24, 2023
Number of pages
93
Written in
2022/2023
Type
Summary
$38.49

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
PracticeExams
4.2
(43)
Sold
343
Followers
194
Items
3263
Last sold
2 days ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions