AP CSA 2.10 Exercise 1: Walking the Word

Unit 2: Selection and Iteration · Lesson 2.10 · Exercise 1

Walking the Word

Implementing String Algorithms. Write real Java, run it, and submit it to be graded against hidden test cases.

Why this one is worth doing

A String is walked with charAt and length, index by index. Every String algorithm on the exam is a loop over those two methods, so this is the pattern rather than one of many.

What to write

  1. Read a single word.
  2. Print how many vowels it contains, counting a, e, i, o and u in lower case only.
  3. Print the word reversed.
  4. Print true when the word reads the same forwards and backwards, and false otherwise.
  5. Print the word with every vowel removed.

Your program reads

A single lower case word.

Your program prints

Four lines: the vowel count, the reversed word, the palindrome check and the word with no vowels.

Worked examples

These are the cases you can see. There are more you cannot, and they use different values, so an answer that prints these numbers as constants will fail.

Example 1 input
racecar
Example 1 output
3
racecar
true
rccr
Example 2 input
java
Example 2 output
2
avaj
false
jv

Your answer

Main.java

Input for the Run button

Run sends whatever is in the input box below. Submitting runs your program against every test case, including hidden ones with different input.


  

  

Stuck?

Hint 1

Building the reverse is one line: put each new character in FRONT of what you have so far.

Hint 2

Compare Strings with equals, never with ==. Two Strings that read the same can still be different objects.

Hint 3

A word made only of vowels leaves an empty last line. An empty line is a correct answer here, not a missing one.

Where to go next

Get in Touch

Whether you're a student, parent, or teacher — I'd love to hear from you.

Just want free AP CS resources?

Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.

Typically responds within 24 hours

Message Sent!

Thanks for reaching out. I'll get back to you within 24 hours.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

[email protected]

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at [email protected]