So I'm trying to print a string backward, but it doesn't start where I want it to. Whenever I run the code it says it starts at -1. Here's my code:
public static String reverse(String str)
{
//This method will return a string that reverses the letters in 'str'
//Example:
// reverse("abcdef") returns "fedcba"
String result="";
for(int i = str.length()-1; i >= 0; i--){
result = result + str.substring(i-1, i);
}
return result;
}
How would I get it to subtract 1 instead of it thinking it's a negative one?
i > 0noti >= 0str.substring(i-1, i)tostr.substring(i, i+1)