• 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: 8919
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sliding this back to the scjp forum
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!