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

 

jebbert@volusia.k12.fl.us > test2021_10_07_APSLHL_firstX
prev  |  next  |  chance

Write a method that returns the first 'howMany' characters in string 'str1'. If the string is not long enough to have 'howMany' characters, return "string not long enough" instead. Look at the test data for examples.


test2021_10_07_APSLHL_firstX("Plot twist!", 4) → "Plot"
test2021_10_07_APSLHL_firstX("this is a very, very, very long string. It is so long you would think that almost any number would be small enough, but that is not true. All it takes is a bigger number than the length of this string.", 52) → "this is a very, very, very long string. It is so lon"
test2021_10_07_APSLHL_firstX("this is a very, very, very long string. It is so long you would think that almost any number would be small enough, but that is not true. All it takes is a bigger number than the length of this string.", 542) → "string not long enough"

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

public String test2021_10_07_APSLHL_firstX(String str1, int howMany) { }

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: 220

Copyright Nick Parlante 2017 - privacy