Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439

As with the other substring method, this one

public String substring(int beginIndex, int endIndex )

creates a new string. The original string is not changed.There are some tricky rules.Essentially, the rules say that if the indexes make no sense,a IndexOutOfBoundsException is thrown.

  1. If beginIndex is negative value, an IndexOutOfBoundsException is thrown.
  2. If beginIndex is larger than endIndex, an IndexOutOfBoundsException is thrown.
  3. If endIndex is larger than the length, an IndexOutOfBoundsException is thrown.
  4. If beginIndex equals endIndex, and both are within range, then an empty string is returned.

Usually, when an exception is thrown your program halts.Future chapters discuss how to deal with exceptions

QUESTION 21:

Decide on what string is formed by the following expressions:

Expression New String Comment
String snake = "Rattlesnake";
snake.substring(0,6)
snake.substring(0,11)
snake.substring(10,11)
snake.substring(6,6)
snake.substring(5,3)
snake.substring(5,12)