I got this message: the left-hand side of an assignment must be a variable when i finished to resolve an excercise about printing a string reversely in recursively-looping. I just want to know if someone could provide an explanation of it? The error message appears in the last line...I don't understand, WHY? There is my code:
import java.util.Scanner;
public class Excersise {
public static void main(String[] args) {
// Create a Scanner
Scanner input = new Scanner(System.in);
//Prompt the user to enter a string
System.out.print("Enter a string: ");
String s = input.nextLine();
reverseDisplay(s);
}
public static void reverseDisplay(String value) {
//Base case
if (value.length() < 2) {
System.out.println(value);
} else {
//Recursion
reverseDisplay(value.substring(1)) + value.charAt(0); <--error
}
}
}
void. What does it mean to add a void to a char?reverseDisplay(value.substring(1));and thenSystem.out.print(value.charAt(0));and also changeprintlntoprintin theifbranch.