Ask coding questions

← Back to all posts
How do I use for-each loops to print out only the books with a capital C in them?
AshtonToland (0)

I have it working where the code prints out all of the books, but can't get it to work print out only books with a C in them.

Commentshotnewtop
a5rocks (732)
for (String C: books)
{
 System.out.println(C);
 
}

This loop needs to have an if condition to check if C has a "C" in it. Maybe use something like string.indexOf and compare the result to -1?