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

 

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

Given an input String, return true if the String is made up of only the same character, repeated over and over. Return false if the input has any variety of characters. Precondition: str will have at least one character.


HINT: This problem is a classic use case of what could be called the "assume, then disprove" type of problem.  Many times in programming, an output checks for "at least one of" or "none of" something.  A useful strategy in these cases is to assume the answer is that all the inputs will match a pattern the same way, with a boolean variable that can only change in one direction (true to false, or false to true) during the checking process.

apcsaLoopsSameCharacter("aaa") → true
apcsaLoopsSameCharacter("Aaa") → false
apcsaLoopsSameCharacter("333333y3333") → false

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

public boolean apcsaLoopsSameCharacter(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