Java (computing revision)

Associate
Joined
14 Sep 2007
Posts
1,057
Location
Southampton
just wanted to check something,

would this work?

string forename = "john"
string surname = "smith"

username = forename.substrings(1, 3) + surname.substring(1, 3);

output would be johsmi?

its a question about string concatenation
 
Associate
Joined
28 Jun 2005
Posts
895
For "johsmi" it would be (0,3)

3 Characters:
0 - 1st char (inclusive)
1 - 2nd char
2 - 3rd char
3 - 4th char (exclusive)
 
Soldato
Joined
9 May 2005
Posts
4,524
Location
Nottingham
|Ric| is correct.

Java API said:
The substring begins at the specified beginIndex and extends to the character at index endIndex - 1. Thus the length of the substring is endIndex-beginIndex.

Code:
["j", "o", "h", "n"]
  ^    ^    ^    ^
  0    1    2    3

["s", "m", "i", "t", "h"]
  ^    ^    ^    ^    ^
  0    1    2    3    4

username = forename.substring(0, 3) + surname.substring(0, 3);
 
Back
Top Bottom