1. What is the difference between double and int data types?
-Int represents interger, and it requires 4 bytes for storage; Double represents floating pint numbers-numbers with decimals, and it requires 8 bytes for storages.
2. how does he syntax for manipulationg numeric data types and objects differ?
-Numeric data type is a primitive data type and it is combined in expressions involving operators, it doesn’t need to be instantiaed. Objects data type is different, it needs to be instantiated before use.
3. Convert the following floating-point numbers to exponential notations:
23.5=2.35E1
0.046=4.6E-2
4. Convert the following numbers from exponential notation to floating-point natation:
32.21E4=322100
55.6E-3=0.00556
5. Give two examples of string literals:
string a=mile
string b=kilometer
6. Why is a variable called a variable?
-Varialbe is an item whose value can change during the execution of a program.
7. Return to the programs in chapter 2 and find an example of each of the different types of variables. Which of the types listed in this subsection are not included?
-bool a=false
-double q=1.234
8. Declare a floating-point variable called payRate and simultaneously initialize it to $35.67.
-double payRate=35.67
9. Declare three integer variables (a,b,c) in a single declaration and simultaneously initialize b to 4.
– int a, c, b=4
10.Give two examples of data that cannot be stored in a variable of type int.
-int q=1.234, or int w=hello
11.There are approximately 2.2 pounds in a kilogram. Name and declare a constant to represent this value.
– final double KILOGRAM=2.2
12. Assume that the integer variable x is 5 and the integer variable y is 10. Give the values of the following expression:
a. x+y*2 == 25
b. x-y+2 ==-3
c. (x+y)*2 ==30
d. y%x == 0
13. Find the syntax errors in the following expressions:
a. a-*b+c : There are more than one arithmetic operators, in this case the subtraction and multiplication, appear together without a number in between.
b. – (a+b)*c): This equation lack of one left parenthesis.
c. (): There is no actual commend but just a pair of parenthesis in the sentence.
14. Assume that x is 4.5 and y is 2. Write the values of the following expression:
a. x/y == 2.25
b. y/x == 0.444
c. x%y == 0
15. Assume that x and y aree of type double and z is of type int. For each of the following assignment statements, state which are valid and which produce syntax errors :
a. x=z: This is valid because z is a less inclusive data type than x is.
b. x=y*z: This is valid because z’s int data type will be autimatically converted to the more inclusive double data type. Since x is in the double data type, it will be valid for it to hold the result.
c. z=x+y: This is not valid since z is assigned to be in int data type, a less inclusive data type than double data type, so z can’t hole the result of x+y, a double data type.
16. Assume that x is of type double and y is of type int. Also assume that x is 4.5 and y is 2. Write the values of the following expressions:
a. (int) x*y == 8
b. (int) (x*y) == 9
17. Assume that x is of type double and y is of type int. Write a statement that assigns the value contained in x to y after rounding this value to the nearest whole number.
y=(int) x
18. Assume that x refers to the string “Wizard” and y refers to the string “Java”. Write the values of the following expressions:
a. y+x = WizardJava
b. y+y.length () + x = Java4Wizard
c. y + “\n” +x + “\n”= Java
Wizard
19. Declare a variable of type String called myInfo and initialize it to your name, address, and telephone number. Each item of information in this string should be followed by a newline character.
– String myInfo= “David \n” +
“\tworcester \n” +
“\t1234567 \n”
20. What is the difference between a message and a method?
– A message is the order sent to the program. A method is the manipulation done by the computer to the message.
21. Describe the purpose of each item of information that appears in a method’s signiture.
– The name of method tells what the method does; the types tells what kinds of data it deals with; the number of its parameters tells how many data the method can work on at a time.
22. State whether each of the following are valid or invalid user-defined symbols in Java:
a. pricePerSquareInch- valid
b. student2- valid
c. 2GuysFromLexington- invalid because starts with a number
d. PI- valid
e. allDone?- invalid because of the question ma rk.
23. Write names for the following items that follow good programming practice:
a. A variable that represents the diameter of a circle– diameterOfCircle
b. A constant that represent the standard deduction for an income tax return– STANDARD_DEDUCTION_FOR_INCOME_TAX
c. A method that draws a rectangle: drawTrangle
24. Describe the role of the items x, y, and z in the satement import x.y.z;.
– x means the overall name of the package; y means the subsection within the package; and z is the name of a particular class in the subsection to be imported.
25. What happens when the computer executes the statement import x.y.*;?
- It imports all the classes within y subsection of x package.