For example, a candy bar item might cost 1.35 with a discount of 0.25 for preferred customers, meaning that preferred customers get it for 1.10. Practiceit / chapter2 / SlashFigure2.java / Jump to. /. Modify the SlashFigure program from the previous exercise to. We use optional third-party analytics. Building Java Programs Ch 3 Lecture on Parameters and Objects from the Math and String class.
Answers to Self-Review Exercises
< BackPage 12 of 14Next >
This chapter is from the book
Java How to Program (early objects), 9th Edition
This chapter is from the book
This chapter is from the book
Answers to Self-Review Exercises
2.1
left brace ({), right brace (}).
if.
//.
Space characters, newlines and tabs.
Keywords.
main.
System.out.print, System.out.println and System.out.printf.
2.2
False. Comments do not cause any action to be performed when the program executes. They're used to document programs and improve their readability.
True.
False. Java is case sensitive, so these variables are distinct.
False. The remainder operator can also be used with noninteger operands in Java.
False. The operators *, / and % are higher precedence than operators + and -.
System.out.printf('%sn%sn', 'This is a Java', 'program');
2.4
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.]
Error: The relational operator => is incorrect. Correction: Change => to >=.