If this is homework, you better understand how the data is stored in a row.
A string can be represented as an array of characters
String line =
char [] data = line.toCharArray();
To cancel an array, you must swap the positions of the elements. First in last, last in first, etc.
int l = data.length;
char temp;
temp = data[0];
data[0] = data[l - 1];
data[l - 1] = temp;
( ) , :
String modifiedString = new String( data );
( ), :
StringBuilder.reverse()
.