removeWhitespace(s)
remove the whitespace in the string referenced
by s
?removeWhitespace(s)
returns a reference to a
new string, which you can then assign to the variable s
via
the assignment statement s = removeWhitespace(s)
. Now, s
refers to the new string, which has the same characters as the original string, but with the
whitespace removed.
\f
), carriage returns (\r
),
and vertical tabs (\0x0B
), but you do not need to worry about them on this assignment.
replace()
and replaceAll()
?String
as the first argument,
replace()
treats it as a string,
whereas replaceAll()
treats it as a regular expression.
removeWhitespace()
by creating a new string and concatenating
together all of the non-whitespace characters?String
object
takes time proportional to \(n^2\).
You may do so using the
StringBuilder
data type
(a mutable version of the String
data type):
repeatedly appending n characters (one at a time) to a StringBuilder
object takes time proportional to n.
Picture
? Create a new Picture
?
Get/set the color of a pixel in a given row and column?Color
object?x
to the nearest integer, with ties rounding up?Math.round(x)
and cast the resulting long
to an int
.
%
) or the
Math.floorMod()
function.
// Returns a new picture that applies an arbitrary kernel filter to the given picture.
private static Picture kernel(Picture picture, double[][] weights)
All of the other kernel filters can be implemented by calling this function with a particular matrix. Note that the method is private, which means that clients cannot call it directly.
However, to get started, we recommend that you implement sharpen()
directly,
to gain experience with manipulating Picture
and Color
objects,
and then attempt kernel()
.
Different boundary conditions work best in different situations. Image-processing libraries often provide the user a choice of boundary conditions.