06.01.2013 Views

Learning Processing: A Beginner's Guide to Programming Images ...

Learning Processing: A Beginner's Guide to Programming Images ...

Learning Processing: A Beginner's Guide to Programming Images ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

308 <strong>Learning</strong> <strong>Processing</strong><br />

Exercise 17-3: Find the duplicates in the following array of Strings.<br />

String words = { "I","love " , " coffee " , " I " , " love " , " tea " } ;<br />

for (int i = 0; i < _______________; i + + ) {<br />

}<br />

for (int j = __; j < _______________; j + + ) {<br />

}<br />

if (___________________) {<br />

}<br />

println(____________ + " is a duplicate. " );<br />

One other feature of String objects is concatenation, joining two Strings <strong>to</strong>gether. Strings are joined with<br />

the “ � ” opera<strong>to</strong>r. Th e plus opera<strong>to</strong>r ( � ), of course, usually means add in the case of numbers. When used<br />

with Strings , it means join .<br />

String helloworld = " Hello " + " World " ;<br />

Variables can also be brought in<strong>to</strong> a String using concatenation.<br />

int x = 10;<br />

String message = " The value of x is: " + x;<br />

We saw a good example of this in Chapter 15 when loading an array of images with numbered fi lenames.<br />

Exercise 17-4: Concatenate a String from the variables given that outputs the following<br />

message.<br />

Th at rectangle is 10 pixels wide, 12 pixels tall and sitting right at (100,100).<br />

float w = 10;<br />

float h = 12;<br />

float x = 100;<br />

float y = 100;<br />

String message = ____________________________________;<br />

println(message);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!