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

 

orion.a.smith@gmail.com hcs-chatbots > apcsaChatbotsRearrangeContainsIYou
prev  |  next  |  chance

Given an input String, first decide if the String contains "I (something) you", like "I will find you". If it does not contain "I (something) you", return "I don't understand". Note that "I (something) you" could occur anywhere in the input. If it does contain "I (something) you", return a response that includes part of the input in the form "Why do you (something) me?" If you are still confused, see the input/output test cases. Note that "I " must be BEFORE " you" in the input in order to work correctly. Also note that specific space characters are integral parts of what to look for in the input, not just the letters.


HINT: use indexOf to find the desired two patterns, and remember their locations.  Use substring to capture a portion of the input, which becomes part of the output.

CHALLENGE: solve in one statement, which can pretty easily be done with a ternary operator.

apcsaChatbotsRearrangeContainsIYou("I like you") → "Why do you like me?"
apcsaChatbotsRearrangeContainsIYou("Help") → "I don't understand"
apcsaChatbotsRearrangeContainsIYou("I am Groot") → "I don't understand"

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

public String apcsaChatbotsRearrangeContainsIYou(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: 230

Copyright Nick Parlante 2017 - privacy