Please open the menu to show more

Friday, July 21, 2017

Java code to print a message without using semicolon

Here i am posting a very interesting java program. It is frequently asked in interviews. In this code i will print a message without using semicolon (ie: ;) 

Understand the code =>

## the printf method in java will print the message and will return the object of PrintStream (it is a pre-defined-class)
since, printf returns an object so we can check a condition inside if statement by comparing the returned object with null

note: null means no object


public class PrintMessageWithoutSemicolon 
{

public static void main(String[] args) 
{

if(System.out.printf(">>>%s<<<","Message printed without using semicolon")!=null)
{

}

}
}

No comments:

Post a Comment