100% found this document useful (14 votes)
57 views

Complete Answer Guide for Solution Manual for Java How to Program, Early Objects (11th Edition) (Deitel: How to Program) 11th Edition

The document provides links to various solution manuals and test banks for programming textbooks, specifically for Java and C++. It includes example exercises and answers related to Java programming concepts, such as arithmetic operators, decision-making statements, and variable declarations. Additionally, it outlines self-review exercises and programming tasks to reinforce learning in Java applications.

Uploaded by

apikanotai
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (14 votes)
57 views

Complete Answer Guide for Solution Manual for Java How to Program, Early Objects (11th Edition) (Deitel: How to Program) 11th Edition

The document provides links to various solution manuals and test banks for programming textbooks, specifically for Java and C++. It includes example exercises and answers related to Java programming concepts, such as arithmetic operators, decision-making statements, and variable declarations. Additionally, it outlines self-review exercises and programming tasks to reinforce learning in Java applications.

Uploaded by

apikanotai
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Visit https://testbankmall.

com to download the full version and


explore more testbank or solution manual

Solution Manual for Java How to Program, Early


Objects (11th Edition) (Deitel: How to Program) 11th
Edition

_____ Click the link below to download _____


https://testbankmall.com/product/solution-manual-for-
java-how-to-program-early-objects-11th-edition-deitel-
how-to-program-11th-edition/

Explore and download more testbank at testbankmall


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Test Bank for Java How To Program (early objects), 9th


Edition: Paul Deitel

https://testbankmall.com/product/test-bank-for-java-how-to-program-
early-objects-9th-edition-paul-deitel/

testbankmall.com

Solution Manual for C++ How to Program 10th by Deitel

https://testbankmall.com/product/solution-manual-for-c-how-to-
program-10th-by-deitel/

testbankmall.com

C++ How to Program 10th Edition Deitel Solutions Manual

https://testbankmall.com/product/c-how-to-program-10th-edition-deitel-
solutions-manual/

testbankmall.com

Test Bank for Principles of Macroeconomics 8th Edition by


Mankiw

https://testbankmall.com/product/test-bank-for-principles-of-
macroeconomics-8th-edition-by-mankiw/

testbankmall.com
Test Bank for Brief Principles of Macroeconomics, 7th
Edition

https://testbankmall.com/product/test-bank-for-brief-principles-of-
macroeconomics-7th-edition/

testbankmall.com

Test Bank for Civil Litigation, 7th Edition

https://testbankmall.com/product/test-bank-for-civil-litigation-7th-
edition/

testbankmall.com

Test Bank for Thinking for Yourself, 9th Edition

https://testbankmall.com/product/test-bank-for-thinking-for-
yourself-9th-edition/

testbankmall.com

Solution Manual for Technical Mathematics, 4th Edition

https://testbankmall.com/product/solution-manual-for-technical-
mathematics-4th-edition/

testbankmall.com

Test Bank for Human Resource Management 15th Edition


Mathis

https://testbankmall.com/product/test-bank-for-human-resource-
management-15th-edition-mathis/

testbankmall.com
Solution Manual for Principles of Managerial Finance,
Brief 8th Edition Zutter

https://testbankmall.com/product/solution-manual-for-principles-of-
managerial-finance-brief-8th-edition-zutter/

testbankmall.com
■ Use arithmetic operators.
■ Learn the precedence of
arithmetic operators.
■ Write decision-making
statements.
■ Use relational and equality
operators.
jhtp_02_IntroToApplications.FM Page 2 Sunday, May 18, 2014 9:41 PM

Self-Review Exercises 2

Self-Review Exercises
2.1 Fill in the blanks in each of the following statements:
a) A(n) begins the body of every method, and a(n) ends the body of
every method.
ANS: left brace ({), right brace (} ).
b) You can use the statement to make decisions.
ANS: if.
c) begins an end-of-line comment.
ANS: //.
d) , and are called white space.
ANS: Space characters, newlines and tabs.
e) are reserved for use by Java.
ANS: Keywords.
f) Java applications begin execution at method .
ANS: main.
g) Methods , and display information in a command win-
dow.
ANS: System.out.print, System.out.println and System.out.printf.
2.2 State whether each of the following is true or false. If false, explain why.
a) Comments cause the computer to print the text after the // on the screen when the pro-
gram executes.
ANS: False. Comments do not cause any action to be performed when the program exe-
cutes. They’re used to document programs and improve their readability.
b) All variables must be given a type when they’re declared.
ANS: True.
c) Java considers the variables number and NuMbEr to be identical.
ANS: False. Java is case sensitive, so these variables are distinct.
d) The remainder operator (%) can be used only with integer operands.
ANS: False. The remainder operator can also be used with noninteger operands in Java.
e) The arithmetic operators *, /, %, + and - all have the same level of precedence.
ANS: False. The operators *, / and % are higher precedence than operators + and -.
2.3 Write statements to accomplish each of the following tasks:
a) Declare variables c, thisIsAVariable, q76354 and number to be of type int.
ANS: int c, thisIsAVariable, q76354, number;
or
int c;
int thisIsAVariable;
int q76354;
int number;
b) Prompt the user to enter an integer.
ANS: System.out.print("Enter an integer: ");
c) Input an integer and assign the result to int variable value. Assume Scanner variable
input can be used to read a value from the keyboard.
ANS: value = input.nextInt();
d) Print "This is a Java program" on one line in the command window. Use method
System.out.println.
ANS: System.out.println("This is a Java program");
jhtp_02_IntroToApplications.FM Page 3 Sunday, May 18, 2014 9:41 PM

3 Chapter 2 Introduction to Java Applications; Input/Output and Operators

e) Print "This is a Java program" on two lines in the command window. The first line
should end with Java. Use method System.out.printf and two %s format specifiers.
ANS: System.out.printf("%s%n%s%n", "This is a Java", "program");
f) If the variable number is not equal to 7, display "The variable number is not equal to 7".
ANS: if (number != 7)
System.out.println("The variable number is not equal to 7");

2.4 Identify and correct the errors in each of the following statements:
a) if (c < 7);
System.out.println("c is less than 7");
ANS: Error: Semicolon after the right parenthesis of the condition (c < 7) in the if.
Correction: Remove the semicolon after the right parenthesis. [Note: As a result, the
output statement will execute regardless of whether the condition in the if is true.]
b) if (c => 7)
System.out.println("c is equal to or greater than 7");
ANS: Error: The relational operator => is incorrect. Correction: Change => to >=.
2.5 Write declarations, statements or comments that accomplish each of the following tasks:
a) State that a program will calculate the product of three integers.
ANS: // Calculate the product of three integers
b) Create a Scanner called input that reads values from the standard input.
ANS: Scanner input = new Scanner(System.in);
c) Declare the variables x, y, z and result to be of type int.
ANS: int x, y, z, result;
or
int x;
int y;
int z;
int result;
d) Prompt the user to enter the first integer.
ANS: System.out.print("Enter first integer: ");
e) Read the first integer from the user and store it in the variable x.
ANS: x = input.nextInt();
f) Prompt the user to enter the second integer.
ANS: System.out.print("Enter second integer: ");
g) Read the second integer from the user and store it in the variable y.
ANS: y = input.nextInt();
h) Prompt the user to enter the third integer.
ANS: System.out.print("Enter third integer: ");
i) Read the third integer from the user and store it in the variable z.
ANS: z = input.nextInt();
j) Compute the product of the three integers contained in variables x, y and z, and assign
the result to the variable result.
ANS: result = x * y * z;
k) Use System.out.printf to display the message "Product is" followed by the value of
the variable result.
ANS: System.out.printf("Product is %d%n", result);
jhtp_02_IntroToApplications.FM Page 4 Sunday, May 18, 2014 9:41 PM

Exercises 4

2.6 Using the statements you wrote in Exercise 2.5, write a complete program that calculates
and prints the product of three integers.
ANS:

1 // Ex. 2.6: Product.java


2 // Calculate the product of three integers.
3 import java.util.Scanner; // program uses Scanner
4
5 public class Product
6 {
7 public static void main(String[] args)
8 {
9 // create Scanner to obtain input from command window
10 Scanner input = new Scanner(System.in);
11
12 int x; // first number input by user
13 int y; // second number input by user
14 int z; // third number input by user
15 int result; // product of numbers
16
17 System.out.print("Enter first integer: "); // prompt for input
18 x = input.nextInt(); // read first integer
19
20 System.out.print("Enter second integer: "); // prompt for input
21 y = input.nextInt(); // read second integer
22
23 System.out.print("Enter third integer: "); // prompt for input
24 z = input.nextInt(); // read third integer
25
26 result = x * y * z; // calculate product of numbers
27
28 System.out.printf("Product is %d%n", result);
29 } // end method main
30 } // end class Product

Enter first integer: 10


Enter second integer: 20
Enter third integer: 30
Product is 6000

Exercises
NOTE: Solutions to the programming exercises are located in the ch02solutions folder.
Each exercise has its own folder named ex02_## where ## is a two-digit number represent-
ing the exercise number. For example, exercise 2.14’s solution is located in the folder
ex02_14.
2.7 Fill in the blanks in each of the following statements:
a) are used to document a program and improve its readability.
ANS: Comments.
b) A decision can be made in a Java program with a(n) .
ANS: if statement.
c) Calculations are normally performed by statements.
ANS: assignment statements.
d) The arithmetic operators with the same precedence as multiplication are and
.
jhtp_02_IntroToApplications.FM Page 5 Sunday, May 18, 2014 9:41 PM

5 Chapter 2 Introduction to Java Applications; Input/Output and Operators

ANS: division (/), remainder (%)


e) When parentheses in an arithmetic expression are nested, the set of paren-
theses is evaluated first.
ANS: innermost.
f) A location in the computer’s memory that may contain different values at various times
throughout the execution of a program is called a(n) .
ANS: variable.
2.8 Write Java statements that accomplish each of the following tasks:
a) Display the message "Enter an integer: ", leaving the cursor on the same line.
ANS: System.out.print( "Enter an integer: " );
b) Assign the product of variables b and c to variable a.
ANS: a = b * c;
c) Use a comment to state that a program performs a sample payroll calculation.
ANS: // This program performs a simple payroll calculation.
2.9 State whether each of the following is true or false. If false, explain why.
a) Java operators are evaluated from left to right.
ANS: False. Some operators (e.g., assignment, =) evaluate from right to left.
b) The following are all valid variable names: _under_bar_, m928134, t5, j7, her_sales$,
his_$account_total, a, b$, c, z and z2.
ANS: True.
c) A valid Java arithmetic expression with no parentheses is evaluated from left to right.
ANS: False. The expression is evaluated according to operator precedence.
d) The following are all invalid variable names: 3g, 87, 67h2, h22 and 2h.
ANS: False. Identifier h22 is a valid variable name.
2.10 Assuming that x = 2 and y = 3, what does each of the following statements display?
a) System.out.printf("x = %d%n", x);
ANS: x = 2
b) System.out.printf("Value of %d + %d is %d%n", x, x, (x + x));
ANS: Value of 2 + 2 is 4
c) System.out.printf("x =");
ANS: x =
d) System.out.printf("%d = %d%n", (x + y), (y + x));
ANS: 5 = 5
2.11 Which of the following Java statements contain variables whose values are modified?
a) p = i + j + k + 7;
b) System.out.println("variables whose values are modified");
c) System.out.println("a = 5");
d) value = input.nextInt();
ANS: (a), (d).
2.12 Given that y = ax3 + 7, which of the following are correct Java statements for this equation?
a) y = a * x * x * x + 7;
b) y = a * x * x * (x + 7);
c) y = (a * x) * x * (x + 7);
d) y = (a * x) * x * x + 7;
e) y = a * (x * x * x) + 7;
f) y = a * x * (x * x + 7);
ANS: (a), (d), (e)
2.13 State the order of evaluation of the operators in each of the following Java statements, and
show the value of x after each statement is performed:
jhtp_02_IntroToApplications.FM Page 6 Sunday, May 18, 2014 9:41 PM

Exercises 6

a) x = 7 + 3 * 6 / 2 - 1;
ANS: *, /, +, -; Value of x is 15.
b) x = 2 % 2 + 2 * 2 - 2 / 2;
ANS: %, *, /, +, -; Value of x is 3.
c) x = (3 * 9 * (3 + (9 * 3 / (3))));
ANS: x = ( 3 * 9 * ( 3 + ( 9 * 3 / ( 3 ) ) ) );
4 5 3 1 2
Value of x is 324.
2.19 What does the following code print?
System.out.printf("*%n**%n***%n****%n*****%n");

ANS:

*
**
***
****
*****

2.20 What does the following code print?


System.out.println("*");
System.out.println("***");
System.out.println("*****");
System.out.println("****");
System.out.println("**");

ANS:

*
***
*****
****
**

2.21 What does the following code print?


System.out.print("*");
System.out.print("***");
System.out.print("*****");
System.out.print("****");
System.out.println("**");

ANS:

***************

2.22 What does the following code print?


System.out.print("*");
System.out.println("***");
jhtp_02_IntroToApplications.FM Page 7 Sunday, May 18, 2014 9:41 PM
jhtp_02_IntroToApplications.FM Page 8 Sunday, May 18, 2014 9:41 PM

7 Chapter 2 Introduction to Java Applications; Input/Output and Operators

System.out.println("*****");
System.out.print("****");
System.out.println("**");

ANS:

****
*****
******

2.23 What does the following code print?


System.out.printf("%s%n%s%n%s%n", "*", "***", "*****");

ANS:

*
***
*****
Other documents randomly have
different content
about donations to the Project Gutenberg Literary Archive
Foundation.”

• You provide a full refund of any money paid by a user who


notifies you in writing (or by e-mail) within 30 days of receipt
that s/he does not agree to the terms of the full Project
Gutenberg™ License. You must require such a user to return or
destroy all copies of the works possessed in a physical medium
and discontinue all use of and all access to other copies of
Project Gutenberg™ works.

• You provide, in accordance with paragraph 1.F.3, a full refund of


any money paid for a work or a replacement copy, if a defect in
the electronic work is discovered and reported to you within 90
days of receipt of the work.

• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.

1.E.9. If you wish to charge a fee or distribute a Project Gutenberg™


electronic work or group of works on different terms than are set
forth in this agreement, you must obtain permission in writing from
the Project Gutenberg Literary Archive Foundation, the manager of
the Project Gutenberg™ trademark. Contact the Foundation as set
forth in Section 3 below.

1.F.

1.F.1. Project Gutenberg volunteers and employees expend


considerable effort to identify, do copyright research on, transcribe
and proofread works not protected by U.S. copyright law in creating
the Project Gutenberg™ collection. Despite these efforts, Project
Gutenberg™ electronic works, and the medium on which they may
be stored, may contain “Defects,” such as, but not limited to,
incomplete, inaccurate or corrupt data, transcription errors, a
copyright or other intellectual property infringement, a defective or
damaged disk or other medium, a computer virus, or computer
codes that damage or cannot be read by your equipment.

1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES - Except for


the “Right of Replacement or Refund” described in paragraph 1.F.3,
the Project Gutenberg Literary Archive Foundation, the owner of the
Project Gutenberg™ trademark, and any other party distributing a
Project Gutenberg™ electronic work under this agreement, disclaim
all liability to you for damages, costs and expenses, including legal
fees. YOU AGREE THAT YOU HAVE NO REMEDIES FOR
NEGLIGENCE, STRICT LIABILITY, BREACH OF WARRANTY OR
BREACH OF CONTRACT EXCEPT THOSE PROVIDED IN PARAGRAPH
1.F.3. YOU AGREE THAT THE FOUNDATION, THE TRADEMARK
OWNER, AND ANY DISTRIBUTOR UNDER THIS AGREEMENT WILL
NOT BE LIABLE TO YOU FOR ACTUAL, DIRECT, INDIRECT,
CONSEQUENTIAL, PUNITIVE OR INCIDENTAL DAMAGES EVEN IF
YOU GIVE NOTICE OF THE POSSIBILITY OF SUCH DAMAGE.

1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If you


discover a defect in this electronic work within 90 days of receiving
it, you can receive a refund of the money (if any) you paid for it by
sending a written explanation to the person you received the work
from. If you received the work on a physical medium, you must
return the medium with your written explanation. The person or
entity that provided you with the defective work may elect to provide
a replacement copy in lieu of a refund. If you received the work
electronically, the person or entity providing it to you may choose to
give you a second opportunity to receive the work electronically in
lieu of a refund. If the second copy is also defective, you may
demand a refund in writing without further opportunities to fix the
problem.

1.F.4. Except for the limited right of replacement or refund set forth
in paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.

1.F.5. Some states do not allow disclaimers of certain implied


warranties or the exclusion or limitation of certain types of damages.
If any disclaimer or limitation set forth in this agreement violates the
law of the state applicable to this agreement, the agreement shall be
interpreted to make the maximum disclaimer or limitation permitted
by the applicable state law. The invalidity or unenforceability of any
provision of this agreement shall not void the remaining provisions.

1.F.6. INDEMNITY - You agree to indemnify and hold the Foundation,


the trademark owner, any agent or employee of the Foundation,
anyone providing copies of Project Gutenberg™ electronic works in
accordance with this agreement, and any volunteers associated with
the production, promotion and distribution of Project Gutenberg™
electronic works, harmless from all liability, costs and expenses,
including legal fees, that arise directly or indirectly from any of the
following which you do or cause to occur: (a) distribution of this or
any Project Gutenberg™ work, (b) alteration, modification, or
additions or deletions to any Project Gutenberg™ work, and (c) any
Defect you cause.

Section 2. Information about the Mission


of Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new computers.
It exists because of the efforts of hundreds of volunteers and
donations from people in all walks of life.

Volunteers and financial support to provide volunteers with the


assistance they need are critical to reaching Project Gutenberg™’s
goals and ensuring that the Project Gutenberg™ collection will
remain freely available for generations to come. In 2001, the Project
Gutenberg Literary Archive Foundation was created to provide a
secure and permanent future for Project Gutenberg™ and future
generations. To learn more about the Project Gutenberg Literary
Archive Foundation and how your efforts and donations can help,
see Sections 3 and 4 and the Foundation information page at
www.gutenberg.org.

Section 3. Information about the Project


Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-profit
501(c)(3) educational corporation organized under the laws of the
state of Mississippi and granted tax exempt status by the Internal
Revenue Service. The Foundation’s EIN or federal tax identification
number is 64-6221541. Contributions to the Project Gutenberg
Literary Archive Foundation are tax deductible to the full extent
permitted by U.S. federal laws and your state’s laws.

The Foundation’s business office is located at 809 North 1500 West,


Salt Lake City, UT 84116, (801) 596-1887. Email contact links and up
to date contact information can be found at the Foundation’s website
and official page at www.gutenberg.org/contact

Section 4. Information about Donations to


the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission of
increasing the number of public domain and licensed works that can
be freely distributed in machine-readable form accessible by the
widest array of equipment including outdated equipment. Many
small donations ($1 to $5,000) are particularly important to
maintaining tax exempt status with the IRS.

The Foundation is committed to complying with the laws regulating


charities and charitable donations in all 50 states of the United
States. Compliance requirements are not uniform and it takes a
considerable effort, much paperwork and many fees to meet and
keep up with these requirements. We do not solicit donations in
locations where we have not received written confirmation of
compliance. To SEND DONATIONS or determine the status of
compliance for any particular state visit www.gutenberg.org/donate.

While we cannot and do not solicit contributions from states where


we have not met the solicitation requirements, we know of no
prohibition against accepting unsolicited donations from donors in
such states who approach us with offers to donate.

International donations are gratefully accepted, but we cannot make


any statements concerning tax treatment of donations received from
outside the United States. U.S. laws alone swamp our small staff.

Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.

Section 5. General Information About


Project Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could be
freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose network of
volunteer support.
Project Gutenberg™ eBooks are often created from several printed
editions, all of which are confirmed as not protected by copyright in
the U.S. unless a copyright notice is included. Thus, we do not
necessarily keep eBooks in compliance with any particular paper
edition.

Most people start at our website which has the main PG search
facility: www.gutenberg.org.

This website includes information about Project Gutenberg™,


including how to make donations to the Project Gutenberg Literary
Archive Foundation, how to help produce our new eBooks, and how
to subscribe to our email newsletter to hear about new eBooks.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

testbankmall.com

You might also like