Complete Answer Guide for Solution Manual for Java How to Program, Early Objects (11th Edition) (Deitel: How to Program) 11th Edition
Complete Answer Guide for Solution Manual for Java How to Program, Early Objects (11th Edition) (Deitel: How to Program) 11th Edition
https://testbankmall.com/product/test-bank-for-java-how-to-program-
early-objects-9th-edition-paul-deitel/
testbankmall.com
https://testbankmall.com/product/solution-manual-for-c-how-to-
program-10th-by-deitel/
testbankmall.com
https://testbankmall.com/product/c-how-to-program-10th-edition-deitel-
solutions-manual/
testbankmall.com
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
https://testbankmall.com/product/test-bank-for-civil-litigation-7th-
edition/
testbankmall.com
https://testbankmall.com/product/test-bank-for-thinking-for-
yourself-9th-edition/
testbankmall.com
https://testbankmall.com/product/solution-manual-for-technical-
mathematics-4th-edition/
testbankmall.com
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
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:
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
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:
*
**
***
****
*****
ANS:
*
***
*****
****
**
ANS:
***************
System.out.println("*****");
System.out.print("****");
System.out.println("**");
ANS:
****
*****
******
ANS:
*
***
*****
Other documents randomly have
different content
about donations to the Project Gutenberg Literary Archive
Foundation.”
• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.
1.F.
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.
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.
Most people start at our website which has the main PG search
facility: www.gutenberg.org.
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.
testbankmall.com