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);
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
or0
in C++, unless we addboolalpha
command.