Monday, September 19, 2011

Concatenating Strings in Assignment 4

In order to compute the Item's id, you should use either the substring or charAt methods of the String class. Note that if you use charAt then you will be concatenating characters together. In this case, you will need to begin the expression by concatenating the empty string to the front of it. So, to concatenate the character 'b' to 'r' you would use the expression "" + 'b' + 'r'. To find out how to extract the first and last characters of a string, go to the Java API and check out the methods available for the String class. The first character is at position 0, but you'll need to compute the index of the last character.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home