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

 

srp4379@lausd.net 2-stringbasics > firstLetter
prev  |  next  |  chance

public String firstLetter(String str)

Given a String, return its FIRST letter.

public String firstLetter(String str) {
  String s = str.substring(0,1);
  return s;
}

NOTE: substring(start, stop) creates (returns) a String using its 2 parameters: start and stop.
The method uses 0-based indexing (the first character is at position 0. NOT 1),

The start parameter specifies at which position the new string should begin.
The stop parameter specifies at which position the new string should stop.
The character at the stop position is NOT used.

Also note that the length of the substring that is created is (stop-start)!

firstLetter("abc") → "a"
firstLetter("123") → "1"
firstLetter("Hollow") → "H"

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

public String firstLetter(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: 10

Copyright Nick Parlante 2017 - privacy