Java Program to Print a Semicolon Without Using Semicolon
The given task is to print a ‘;‘ without using ‘;‘ anywhere in the code. The simplest idea one can think of to approach this interesting question is using ASCII value somehow in the program. But as Java does not support macros, unlike C/C++, therefore to eliminate ‘;’ at the end of every line in code is to use, if-statement or while loop with printf(String, Object) method of PrintStream in the condition statement. The main logic here is as printf() returns PrintStream object which is not null so on comparison it with null (literal in Java) we will get our desired output.
Method 1: Using if statement
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
Method 2: Using while loop