Page 136 - Introduction to Programming with Java: A Problem Solving Approach
P. 136
102 Chapter 3 Java Basics
§3.22 Strings
37. What two operators perform string concatenation, and what’s the difference between the operators?
38. What method can be used to retrieve a character at a specified position within a string? 39. What two methods can be used to compare strings for equality?
§3.23 Input—the Scanner class
40. What is whitespace?
41. Write the statement that you must put before any other code to tell the compiler that you will be using the
Scanner class.
42. Write the statement that creates a connection between your program and the computer’s keyboard.
43. Write a statement that inputs a line of text from the keyboard and puts it into a variable named line.
44. Write a statement that inputs a double number from the keyboard and puts it into a variable named
number.
Exercises
1. [after §3.3] Illustrate the two ways to provide comments in a Java program by writing the following as a comment in both formats:
This a very long comment with lots of useless and unnecessary words that force us to use multiple lines to include it all.
When using the block syntax, minimize your use of asterisks.
2. [after §3.5] Why does public static void Main(String[] args) generate an error?
3. [after §3.6] What are braces used for?
Apago PDF Enhancer
4. [after §3.8] What program is in charge of
a) Reading Java source code and creating bytecode? b) Executing bytecode?
5. [after §3.9] To enhance readability of an identifier that’s comprised of several words, use periods between the words. (T / F)
6. [after §3.10] For each of the below variable names, indicate (with y or n) whether it’s legal and whether it uses proper style. Note: You may skip the style question for illegal variable names since style is irrelevant in that case.
legal (y/n)?
proper style (y/n)?
a) _isReady b) 3rdName
c) num of wheels d) money#on#hand
e) taxRate
f) SeatNumber
7. [after §3.10] You don’t need a semicolon after a variable declaration. (T / F)
8. [after §3.13] If we just write a floating point number without specifying its type, what type does the
computer assume it is?
9. [after §3.14] How would you specify the square root of two as a named constant? Use 1.41421356237309 for your named constant’s value.
10. [after §3.15] Write the following mathematical expressions as legal Java expressions:
a) ⎛3k⎞2 ⎝4⎠