java – unexpected type error

java – unexpected type error

The problem is here:

myStr.charAt(j) += reversed;

The left-hand-side is a value. Not a variable. Thats why you cant to a += to it.

Although it defeats the purpose of learning how do it the hard way, you can do it like this:

myStr = new StringBuffer(myStr).reverse().toString();

it sould be reversed += new String(myStr.charAt(j)); … the unexpected type is that what charAt(j) returns

java – unexpected type error

String myStr = abcdef;
String reversed = ;

for(int j = myStr.length()-1 ; j >= 0; j--)
     reversed += myStr.CharAt(j);

Leave a Reply

Your email address will not be published.