+ 4
How do i store the first character of a word in a char variable?
3 Réponses
+ 10
char first = word.charAt(0);
+ 7
0 is the starting index, so to get the first character it's always 0.
example:
String word = "cool burgers";
Index -> char
0 -> 'c'
1 -> 'o'
2 -> 'o'
3 -> 'l'
4 -> ' '
etc..
12 = word.length() - 1 -> 's'
charAt() returns the character at the index in the paranthesis, index 0 being the first char in the string.
+ 3
how do I know what number to put in the parenthesis ?