189k views
4 votes
Assume myString and yourString are variables of type String already declared and initialized. Write ONE line of code that sets yourString to the first character and the last character of myString added to myString variable.

1 Answer

4 votes

Answer:

line of code :

newString=myString+myString.charAt(0)+myString.charAt(myString.length()-1);

Step-by-step explanation:

In Java, the + is used for concatenation

method

charAt() will return the character from the given index from string

myString.charAt(0) will return E

myString.charAt(myString.length()-1)

User Strangelove
by
5.3k points