• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Ternary operator problem

 
Vivian Josh
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I could not understand why the following problem gives compilation error.

public class ObjectTest {

public static void main(String[] args) {
byte b = 0;
(true) ? b = b + 1 : b = 100;

System.out.println("Output: " + b);
}
}


Even if try to assign left hand variable it still gives problem.

Can some one explain me this problem?

Any help would be nice.

Thanks,
Vivian
 
Bert Bates
author
Sheriff
Posts: 8905
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sliding this back to the scjp forum
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic