Friday, June 7, 2013

Print String Without Semicolon by Java Code

Print String Without Semicolon by Java Coding. It is very tricky as System.out.println() and some System.out.print() return void unlike printf() in C. So we have to choose System.out.print() which returns PrintStream. The syntax is:: System.out.print(String,Object[]) or System.out.print(Locale,String,Object[]). These two System.out.print() only return something(PrintStream).

Here is the code.

/**
 *PrintStringWithoutSemicolon.java
 *
 * @author 
 * Santanu Kar
 **/

public class PrintStringWithoutSemicolon {

    public static void main (String[] args) {
while(System.out.printf("santanu kar\n")==null){
}
}    
}


OR

/**
 *PrintStringWithoutSemicolon.java
 *
 * @author 
 * Santanu Kar
 **/

public class PrintStringWithoutSemicolon {

    public static void main (String[] args) {
if(System.out.printf("santanu kar\n")==null){
}
}
}

No comments:

Post a Comment