id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

orion.a.smith@gmail.com apcsa-loops > apcsaChatbotsPunctuatedWord
prev  |  next  |  chance

Given an input String, determine whether any of the words end with a comma or period. Note that what this means is that the character before the comma or period is a letter (which you can check using Character.isLetter(str.charAt(index)), returning true or false), since some of the inputs will either have no commas and no periods, or will have them in other locations. A word may have all sorts of things AFTER the comma or period. So long as you find a comma or period with a letter before it, return true.


HINT: it's probably easiest to use a for loop on this problem, so that when you find a period or comma, you then look before that character for a letter.

CHALLENGE: Solve in one statement.  Probably requires regular expressions.

apcsaChatbotsPunctuatedWord("Hello world") → false
apcsaChatbotsPunctuatedWord("Hello, world") → true
apcsaChatbotsPunctuatedWord("Hi. How are you?") → true

...Save, Compile, Run (ctrl-enter)

public boolean apcsaChatbotsPunctuatedWord(String str) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 210

Copyright Nick Parlante 2017 - privacy