Java Practice Problems
Sort by: Curriculum unit & section · Just problems, by category
Show: Everything · Lessons · Worksheets · Problems
- Build the line: declare and initialize temperature 1.1 Worksheet 🌶️ Click the tokens below, in order, to build a line that declares an integer variable named…
- Introduction to Algorithms 1.1 Worksheet 🌶️ An algorithm is an ordered series of steps to solve a problem. Let's say that you are …
- Parsons problem: Hello World structure 1.1 Worksheet 🌶️ Arrange the lines below to build a working Hello World program, with each line indented c…
- Visualizer: Quick Reference 1.1 Lesson 🌶️ Some problems ask your method to accept a `Visualizer` parameter — usually named `viz`. W…
- plotPoint Geometry & Shapes 1.2 Write a method that plots a point at (x, y) in the color given, then prints "plotted" (no…
- Declare a student record Java Basics 1.2 🌶️ A student is taking 6 courses, has a GPA of 3.5, is currently enrolled, and is named Mari…
- Line trace: swapping two values with temp 1.3 Worksheet 🌶️ Below is a method that swaps two values using a temp variable. Trace a, b, and temp immed…
- Print two lines with one statement Java Basics 1.3 🌶️ Write code in the box that prints these two lines, using a single System.out.println stat…
- Seconds to minutes and seconds Java Basics 1.3 🌶️🌶️ The variable totalSeconds holds a length of time in seconds. The three locked lines at th…
- Split a two-digit number Java Basics 1.3 🌶️ The variable number holds a two-digit whole number. The two locked lines at the bottom pr…
- Swap two values Java Basics 1.4 🌶️🌶️ The program below gives first and second their starting values, and its last two lines (l…
- Update an account balance Java Basics 1.4 🌶️ The variable balance holds the amount in an account, deposit is a deposit being made, and…
- Round to the nearest whole number Java Basics 1.5 🌶️🌶️ The variable temperature holds a positive temperature with a decimal part, like 71.6. The…
- printAverage Java Basics 1.5 🌶️ The method below is supposed to calculate the average number of points scored per game an…
- Average of four test scores Java Basics 1.5 🌶️🌶️ test1, test2, test3 and test4 are four whole-number test scores. The locked line at the b…
- Boolean Operators: Quick Reference 2.1 Worksheet 🌶️ This page reviews the three boolean operators you'll use constantly in conditionals, then…
- Truth table: && vs || 2.2 Worksheet 🌶️ Complete the truth table below for the two boolean expressions.
- Venn diagram: A && !B 2.2 Worksheet 🌶️ Shade the region(s) of the diagram where the expression below is true.
- Venn diagram: (a || b) && !c 2.3 Worksheet 🌶️🌶️ Shade the region(s) of the diagram where the expression below is true.
- Venn diagram: four sets 2.3 Worksheet 🌶️🌶️🌶️ Shade the region(s) of the diagram where the expression below is true.
- sumDigits One Loop 2.4 🌶️🌶️🌶️ Given a non-negative int n, return the sum of its digits. sumDigits(126) returns 9 (1+2+6…
- caesarShiftString One Loop 2.7 🌶️🌶️🌶️ Extra Write a method that takes one String parameter, s, and one int parameter, shift, and retu…
- Vector2D.Magnitude Objects & Classes 3.5 🌶️ Below is the definition of a Vector2D class, representing a two dimensional vector - an …
- printSquares One Loop 4.2 Given n, print the square of each integer from 1 to n, one per line, using System.out.pri…
- Trace: cumulative even sum 4.4 Worksheet Consider the code below. Assume it compiles and runs correctly. ```java int total = 0; f…
- Trace: palindrome check indices 4.4 Worksheet 🌶️🌶️ Below is the loop from a palindrome checker for the String s = "level" (length 5). Trace …
- Parsons problem: Point constructor 5.1 Worksheet Below are candidate lines for a Point class's constructor, which takes parameters px and …
- capitalizeAll One Loop 6.3 Given an ArrayList<String> of words, return a new ArrayList<String> containing each word …
- sumFile Files & I/O 6.4 Given a File containing one integer per line, construct your own Scanner over it and retu…
- findMax 2D Arrays 8.3 Given a 2D array of ints, draw the grid, find the maximum value, highlight the cell it wa…
- transpose 2D Arrays 8.4 Given a rectangular 2D array grid, return its transpose: a new 2D array where rows and co…
- Trace: factorial recursive calls 10.1 Worksheet 🌶️🌶️ Below is a recursive factorial method. Trace every call and every return as factorial(4) …
- Trace: fibonacci recursive calls 10.2 Worksheet 🌶️🌶️🌶️ Below is a recursive (non-memoized) Fibonacci method. Trace every call and every return a…