192k views
4 votes
Assume that name is a variable of type string that has been assigned a value . write an expression whose value is the first character of the value of name . so if the value of name were "smith" the expression 's value would be 's'.

User Loqman
by
5.2k points

1 Answer

4 votes

For the first question, you would just add the parenthesis to the string mutation1:

String word = "sadly";

String mutation1 = "(" + word + ")";

For the second you need the method substring from the String class:

It is defined as String.substring(begining, ending);

String name = "Smith";

String firstCharacter = name.substring(0, 1);

0 is considered the beginning of the string, then you get the next 1 characters.

User Mashawn
by
5.1k points