AP Computer Science A
Exercises
51 exercises. Your progress is kept in this browser only.
Using Objects and Methods
Volume of a box
Declaring variables and using them in an expression
Perimeter of a rectangle
Combining parameters in an arithmetic expression
Hours to seconds
Converting between units with multiplication
Average of three
Using double for a value that is not a whole number
Positive or not
Returning a boolean from a comparison
Area of a rectangle
Calling a method with parameters and returning a value
Even or odd
Using the remainder operator and returning a boolean
What is left over
Using the remainder operator
Last digit
Extracting a digit with the remainder operator
Tens digit
Combining integer division and remainder
Money in cents
Converting to a single unit before calculating
How many quarters
Using integer division deliberately
Minutes left over
Reading a total as whole units plus a remainder
Say hello
Printing with System.out.println and joining Strings
Say it twice
Calling System.out.println more than once
Label a value
Joining text and numbers with +
Put it in quotes
Escaping a double quote inside a String
Two columns
Using the tab escape sequence
A Windows path
Escaping a backslash
A tiny receipt
Printing several lines that build one block of output
Add a tip
Updating a variable with +=
Spend some money
Updating a variable with -=
Double it twice
Updating a variable with *=
Halve it twice
Updating with /= and seeing integer division bite
Chop off the decimals
Casting a double to an int throws away the fraction
Round to the nearest whole number
Rounding with Math.round and casting the result
Average of two whole numbers
Avoiding integer division when the answer is not whole
What percentage
Ordering an expression so integer division does not destroy it
Celsius to Fahrenheit
Arithmetic with doubles, and integer division as a trap
Milliseconds in a day
Choosing a type large enough for the result
How long is it
Calling length() on a String
First letter
Taking one character out with substring
Last letter
Using length() to find the end of a String
The middle letter
Using substring with two positions
Shout it
Calling toUpperCase
Whisper it
Calling toLowerCase
Where does it appear
Calling indexOf and understanding -1
Are they the same word
Comparing Strings with equals rather than ==
Same word, any capitals
Calling equalsIgnoreCase
Initials
Calling String methods and building a String
Distance from zero
Calling Math.abs
How far apart
Combining subtraction with Math.abs
Square root
Calling Math.sqrt
Raise to a power
Using Math.pow and casting its double result
The bigger one
Calling Math.max
The largest of three
Nesting one method call inside another
Tidy up the spaces
Calling an instance method that returns a new object
Make it a hashtag
Calling replace on a String object
Is it in there
Calling contains and returning what it gives back
Put a name together
Chaining instance methods together
