home—info—lects—labs—exams—hws
tutor/PIs—java.lang docs—java.util docs
hw00
hw00
finger exercises
Due Date: Sep.06 (Mon.) in class (or, by Tues 17:00
1)
Instructions:
-
Type in answers to each of the following questions, in a computer file
(any text editor will do fine 2; if using something like Microsoft Word,
please save-as a plain text file).
-
Save your as a text file, and submit it via Blackboard.
[via Blackboard > Course Tools > Assignments > hw00 > Add attachment.]
-
In addition, turn in a hardcopy as you come to class.
All homeworks will work the same way:
submit via Blackboard, and turn in a hardcopy in class.
-
Problems worth 0pts don't require an answer.
-
(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”.)
- (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).
- (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.
- 2+3*4
- 2+(3*4)
- (2+3)*4
- 13.0 / 5.0
- 13 / 5
- 13 % 5
- Math.sqrt(25)
(the built-in function Math.sqrt
returns the square-root of a number)
- Math.PI
-
12 ^ 10 =
- Math.sqrt( 3*3 + 4*4 )
- Math.sqrt( Math.sqrt(16) )
- 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).
- (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.
- "There are " + (1+2+3+4) + " bowling pins."
- "There are " + 1+2+3+4 + " bowling pins."
- 1+2+3+4 + "is the number of bowling pins."
-
Object120.length("hel" + "lo")
(See lab01b—Strings for how to add
class Object120
to your project.)
-
Object120.toUpperCase("HeLlO?")
-
Object120.substring( Object120.toUpperCase("howdy"), 2, 4 ) + 40
-
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).
- (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. ↩
home—info—lects—labs—exams—hws
tutor/PIs—java.lang docs—java.util docs