Printf in Java from C/C++

text zoom

In 5.0, the Java™ programming language introduces a new output formatter method printf like C Language. The printf method is introduced in the java.io.PrintStream class of java. The general syntax of the printf method is as follows :-


 


printf(Locale l,String format, Object...args) and,


printf(String format, Object...args)


 


Example:-


 


The following example will demonstrate the use of printf method.


 


package com.visualbuilder;


public class PrintfExample {
    public static void main(String[] args) {
            System.out.printf("I got %d marks",10);
        }
}


 


Output:-


 


The following output gets printed on the console.


I got 10 marks

                    

Copyright © 2013 VisualBuilder. All rights reserved