-1

I am going through the book "Learn Java for Android Development" 3rd edition by Jeff Friesen. One early example is giving me an error on lines 11 and 12 ( "A" +" "B") and ("A" + 5) lines. Copied exactly from the book, but got the error "the left hand side of an assignment must be a variable" in Eclipse. Can you help me figure out what is wrong with my code?

public static void main (String[] args)
{
    int age = 65;
    System.out.println(age + 32);
    System.out.println(++age);
    System.out.println(age--);
    System.out.println( "A" = "B" );
    System.out.println( "A" = 5);
    short x = 32767;
    System.out.println(++x);
}

}

  • Plus or equal sign? Typo? Experiment? – laune Jan 15 '15 at 17:37
  • possible duplicate of [Left-hand side of assignment must be a variable](http://stackoverflow.com/questions/11243805/left-hand-side-of-assignment-must-be-a-variable) – default locale Jan 15 '15 at 17:38
  • You've written `("A" + "B")` in the question, but `("A" = "B")` in the code. Which is in the book? – Jon Skeet Jan 15 '15 at 17:39
  • It's "A" + "B". I type'od. Thanks! Responses come fast! – strHeelJack Jan 15 '15 at 17:41
  • 2
    So you just confused `=` and `+` and your code is now working? Then this question was caused by a simple typographical error and should therefore be deleted. – honk Jan 15 '15 at 17:48

2 Answers2

0

Based on your description, it looks like you typo'd.

Perhaps you want this?

System.out.println( "A" + "B" );
System.out.println( "A" + 5);
Ryan J
  • 8,275
  • 3
  • 25
  • 28
-1

Adding one more thing to this for learning:

You can still use == operator, which is equality operator in this statement. So if you write

System.out.println( "A" == "B" );

Then this line will print false, because "A" is not equal to "B". So it is not that we can not use operators but the expression should be conclusive, it produces some output.

Similarly

System.out.println( A = "B" );

will print B if the variable A has been declared already. This line assignes value "B" to a string variable A and then prints it.

Good Luck in learning