In this assignment, we will go through basic Java syntax concepts. To help ease the introduction, equivalent concepts are also shown in Python. This homework does NOT require that you know Python. Even if you don’t know Python, you’ll see that Python code is almost like pseudocode and should therefore be readable.
This tutorial assumes that you have significant (one semester) experience with at least some programming language, and is intended only to highlight the Java way of doing some previously familiar things. If you don’t have prior experience, please feel free to contact the staff if you need extra assistance.
This homework is due on Friday, August 25! Early lectures, labs, and projects will rely on being able to read and understand the basic structure of Java code.
Crash Course #
For ease of navigation, this crash course has been split up into several parts. Feel free to skim and read at whatever pace you feel comfortable with. You can start the exercises even before you finish reading part A - we recommend doing the reading and the exercises concurrently.
UW has a large collection of introductory Java exercises that we will be borrowing. For HW 0, create an account on Practice-It, and complete the following:
- Self-Check 1.26: Confusing
- Exercise 2.5:
- Self-Check 2.25:
- Exercise 3.23:
printIndexedor Exercise 4.17:
- Self-Check 4.5:
- Exercise 4.19:
Make sure to follow the directions on the exercise page, especially for printing versus returning!
If you run into trouble with the exercises, one strategy could be solving in Python first, then translating that to Java. If you’re having trouble with solving in Python, that’s fine, and not the point of this exercise. If you’d like to reference Python solutions, see the dropdowns below.
for i in range(5): line = "" for j in range(i + 1): line += "*" print(line)
def printIndexed(s): output = "" for i in range(len(s)): output += s[i] output += str(len(s) - 1 - i) print(output)
def stutter(s): output = "" for i in range(len(s)): output += s[i] output += s[i] return output
def quadrant(x, y): if x == 0 or y == 0: return 0 elif y > 0 and x > 0: return 1 elif y > 0 and x < 0: return 2 elif y < 0 and x < 0: return 3 else: return 4
Once you’ve completed the 6 exercises, go to your list of solved problems, take a screenshot of the table, and submit the screenshot to HW 0 on Gradescope.
NOTE: If you are having trouble getting your screenshot into the PDF format required by Gradescope, try using this converter.
Congratulations! You’re prepared for the next few lectures, and have completed HW 0.
A programming language is not too different from a spoken language – in
particular, you will get better the more code you write. The PracticeIt site
has many problems available, and you should feel free to attempt more.
(Their progression doesn’t exactly match ours, though – if you see a
or need to generate a random number, you can skip that problem.)
We also recommend https://codingbat.com/java/AP-1, which has more advanced Java problems.