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

 

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

Given an input String, find and return the two-character String representing the "highest" character in the input (i.e., the character which comes later in an ordering of characters than all others), followed by the second-highest character. If there are multiple instances of the highest character, the output will look like the highest character twice, like "zz" or "NN". Precondition: str will have at least two characters.


See the prior problem apcsaLoopsMaxCharacter for more advice on extracting and comparing String characters.

HINT: You will need to keep track of multiple variables to do this problem correctly.  There is a reason this problem is in sequence after the prior two problems.  You may find it easier to use more than one loop, though the way you use the second loop may not be the way you are used to.

apcsaLoopsMaxTwo("ab") → "ba"
apcsaLoopsMaxTwo("Xena") → "ne"
apcsaLoopsMaxTwo("1234567890") → "98"

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

public String apcsaLoopsMaxTwo(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: 250

Copyright Nick Parlante 2017 - privacy