pribic's blog

By pribic, history, 4 years ago, In English

A lot of time we have seen problems where we need to output a YES or No. Usual way of doing this is flag ? "YES" : "NO" however many programming language supports directly printing boolean as True or False.

So is there any specific reason we are asked to print YES/NO instead TRUE/FALSE?

Here is a simple diff between both approach:

System.out.println(flag? "YES" : "NO" );

vs

System.out.println(flag);

  • Vote: I like it
  • -25
  • Vote: I do not like it

| Write comment?
»
4 years ago, # |
  Vote: I like it +30 Vote: I do not like it

This isn't a usual way to do this. Not everybody store YES/NO answer in a variable. More often, it's multiple checks like if(...) { print("YES"); return; }.

And you're suggesting something convenient for Java. Your new improved line would print 1 or 0 in C++, unless we add boolalpha command.