The problem is that you are trying to assign a char type to a String type and this is not allowed since these types are incompatible.
You declared LastChar as a String but in your code you do this:
LastChar = Input.charAt(LastIndex);
As the String.charAt method returns a char, the things go wrong.
Some info about String and char:
- char is a primitive type and represents a single character: 'a', 'D'. Notice that you always use single quotes (') to represent a char literal.
- String is an object which represents a string of characters: "abcd". Notice that you always use double quotes (") to represent a String literal.
So the solution for your problem is to change the LastChar type to char:
Furthermore you need to change the lines:
and
To:
and
Pay attention to the single quotes. If you say:
The java compiler will interpret "?" as a String with only one character and not as a char.
Greetings.