In this program, we use a if statement and System.out.printf()
because it returns object of PrintStream
which is not null
when something is passed to the printf()
.
public class Main {
public static void main(String[] args) {
if (System.out.printf("Hello World 👋") != null) {}
}
}
whereas, System.out.println()
and System.out.print()
return void
which cannot be used for a comparison.
Top comments (5)
Why?
can you elaborate on the question plz?
Sure. Why, as in, why would you want to deliberately use code smells, such as an empty block, etc, just to avoid a semicolon?
It's nothing but a quiz question which was asked in my university, and I thought it would be nice for the community to know it, out there. 😁
Wow, that's an unexpected (and unfair) question for a programming instructor to ask on a quiz, a question that can only be answered by using code smells.