RU beehive logo ITEC dept promo banner
ITEC 120
2010fall
ibarland

homeinfolectslabsexamshws
tutor/PIsjava.lang docsjava.util docs

hw00
hw00
finger exercises

Due Date: Sep.06 (Mon.) in class (or, by Tues 17:00 1)

Instructions:

  1. (learning style, 3pts) Take the Index of Learning Styles Questionnaire.
    What are your four scores? (e.g. “ACT 5, INT 2, …”. Be sure to include the name with each number; if you only write “5”, I can't tell if you mean “ACT 5” or “REF 5”.)
  2. (0pts) Reading assignment: §§ 1.4, 2.1, 2.2, 2.3 (named, respectively, "The Java Programming Language", "Character strings", "Variables and Assignment", "Primitive data types").
    You can browse over concepts that weren't mentioned in lecture (e.g. the primitive types like long), but be sure you understand the concepts that were mentioned in lecture (e.g. declaring a variable on one line, and initializing it on the next).
  3. (5pts) What do each of the following Java expressions evaluate to?
    Before typing them in, think to yourself what you think the answer should be; feel free to note if any surprising or puzzling results.
    1. 2+3*4
    2. 2+(3*4)
    3. (2+3)*4
    4. 13.0 / 5.0
    5. 13 / 5
    6. 13 % 5
    7. Math.sqrt(25) (the built-in function Math.sqrt returns the square-root of a number)
    8. Math.PI
    9. 12 ^ 10 =                 
    10. Math.sqrt( 3*3 + 4*4 )
    11. Math.sqrt( Math.sqrt(16) )
    12. Math.sqrt( Math.abs(-16) ) (the built-in function Math.abs returns the absolute value of a number)
    Notice how, in the last three examples, you compute an intermediate result, and then pass that result as an input to another function (the (outermost) Math.sqrt).
  4. (5pts) What do each of the following Java expressions evaluate to?
    Before typing them in, think to yourself what you think the answer should be; feel free to note if any surprising or puzzling results. If the answer is a String, you should include double-quotes around it.
    1. "There are " + (1+2+3+4) + " bowling pins."
    2. "There are " + 1+2+3+4 + " bowling pins."
    3. 1+2+3+4 + "is the number of bowling pins."
    4. Object120.length("hel" + "lo")
      (See lab01b—Strings for how to add class Object120 to your project.)
    5. Object120.toUpperCase("HeLlO?")
    6. Object120.substring( Object120.toUpperCase("howdy"), 2, 4 ) + 40
    7. Re-write the previous expression so that it explicitly calls Object120.intToString to convert 40 into a String. (As given, the conversion is done for you behind your back.) Give the expression, not the result (which should be the same as before).
  5. (2pts) Java has function (method) which raises one number to another. Look at the documentation for class Math, and find it. (Hint: Alphabetically, it's between “max” and “signum”; the method summaries near to the top of the page are listed alphabetically.)
    Write a java expression3 computing 220 (a.k.a. 1 Meg — a bit over a million), using this function.

1Homeworks are usually due at the start of class; the Tue deadline is there this week, in case you have trouble finding a computer running BlueJ, or otherise run in to unexpected snags; you'll still have an opportunity to come to office hours before the due-date.      

2You could even use BlueJ's editor, if you like.      

3I'm asking for the expression, not the numeric result.      

homeinfolectslabsexamshws
tutor/PIsjava.lang docsjava.util docs


©2010, Ian Barland, Radford University
Last modified 2010.Sep.08 (Wed)
Please mail any suggestions
(incl. typos, broken links)
to iba�rlandrad�ford.edu
Powered by PLT Scheme