View Single Post
  #2 (permalink)  
Old 08-07-2007, 06:22 AM
cachi cachi is offline
Member
 
Join Date: Jul 2007
Posts: 40
cachi is on a distinguished road
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:

Code:
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:
Code:
char LastChar;
Furthermore you need to change the lines:
Code:
if ( LastChar == "?" ){
and
Code:
if ( LastChar == "?" ){
To:
Code:
if ( LastChar == '?' ){
and
Code:
if ( LastChar == '?' ){
Pay attention to the single quotes. If you say:

Code:
(LastChar == "?")
The java compiler will interpret "?" as a String with only one character and not as a char.
Greetings.
Reply With Quote