title: How do I find the second to last character of a string?
body: <p>I'm trying to find the second to last character of a string. I try using <code>word.length() -2</code> but I receive an error. I'm using java</p>
  
  <pre><code>String Word;
  char c;
  
  lc = word.length()-1;
  slc = word.length()-2; // this is where I get an error.
  System.out.println(lc);
  System.out.println(slc);//error
  </code></pre>
  
  <p>Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -1
      at java.lang.String.charAt(Unknown Source)
      at snippet.hw5.main(hw5.java:30)</p>