Download 3.2

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Law of large numbers wikipedia , lookup

Big O notation wikipedia , lookup

Elementary mathematics wikipedia , lookup

Transcript
Homework 3.2
♫ What is the difference between double and int data types?
♪ Int stands for integer.
♪ Double stands for all real numbers.
♫ How does the syntax for manipulating numeric data types and objects differ?
♪ Numeric number types is for adding and subtracting and objects are sent
messages.
♫ Convert the following floating-point numbers to exponential notation:
♪ 23.5 = 2.35E1
♪ 0.046 = 4.6E-3
♫ Convert the following numbers from exponential notation to floating-point notation:
♪ 32.21E4 = 322,100
♪ 55.6E-3 = 0.0556
♫ Give two examples of string literals.
♪ “Enter degrees Fahrenheit.”
♪ “Enter the circumference of the circle.”
♫ Why is a variable called a variable?
♪ Because it stands in place of something else.
♫ Declare a floating-point variable called a payRate and simultaneously initialize it to
$35.67.
♪ double payRate = 3.567E1;.
♫ Declare three integer variable (a, b ,c) in a single declaration and simultaneously
initialize b to 4.
♪ int a, b = 4, c; .
♫ Give two types of data that cannot be stored in a variable of type int.
♪ Fractions and decimals.
♫ There are approximately 2.2 pounds in a kilogram. Name and declare a constant to
represent this value.
♪ Final double KILOGRAM = 2.2;.
♫ Assume that the integer variable x is 5 and the integer variable y is 10. Give the
values of the following expressions.
♪ x + y * 2 = 25
♪ x – y + 2 = -3
♪ (x + y) * 2 = 30
♪ y%x=5
♫ Find the syntax errors in the following expressions:
♪ a - * b + c = subtract and multiply cannot be next to each other.
♪ - ( a + b ) * c) = the last parentheses must have a counterpart.
♪ ( ) = there are no variables.
♫ Assume that x is 4.5 and y is 2. Write the values of the following exercises:
♪ x / y = 2.25
♪ y / x = 0.44
♪ x%y= 2
♫ Assume that x and y are 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:
♪ x = z syntax error
♪ x = y * z syntax error
♪ z = x + y ok
♫ Assume that x is of the type double and y is of the type int. Also assume that x is 4.5
and y is 2. Write the values of the following expressions:
♪ (int) x * y = 8
♪ (int) (x * y) = 9
♫ 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 = -5.2 n = (int) ( x – 0.5)
♫ Assume that x refers to the string “Wizard” and y refers to the string “Java”. Write
the values of the following expressions:
♪ y + x = “JavaWizard”
♪ y + y.length( ) + x = Java4Wizard
♪ y + “\n” + x + “\n” = Java
Wizard
♫ 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
myInfo = “McKinley Craft \n” + “822 Jefferson Ave N \n” + “980- 3518 \n”
♫ Describe the purpose of each item of information that appears in a method’s
signature.
♪ What type of value it returns.
♪ Its name.
♪ The number and type of the parameters it expects.
♫ State whether each of the following are valid or invalid user-defined symbols in Java:
♪ a. pricePerSquareInch = valid
♪
♪
♪
♪
b. student2 = valid
c.2GuysFromLexington = invalid
d.PI = invalid
e.allDone? = invalid
♫ Write names for the following items that follow good programming practice:
♪ a. A variable that represents the diameter of a circle. = Diameter
♪ b. A constant that represents the standard deduction for an income tax return. =
STANDARDDEDUCTION
♪ c. A method that draws a rectangle. = DrawRectangle
♫ Describe the role of the items x, y, and, z in the statement import x.y.z;.
♪ X is the overall name of the package , y is the name of a subsection within the
package, and z is the name of a particular class in the subsection.
♫ What happens when the computer executes the statement import x.y.*;?
♪ The star makes all classes in a package available.
♫ Assume that a program needs to use the class Format, which is included in the
package BreezySwing. Show two ways to import this class with Java import
statements.
♪ BreezySwing.Format;
♪ BreezySwing.*;