Блог пользователя pribic

Автор pribic, история, 4 года назад, По-английски

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);

  • Проголосовать: нравится
  • -25
  • Проголосовать: не нравится

»
4 года назад, # |
  Проголосовать: нравится +30 Проголосовать: не нравится

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.