Monday, 22 February 2016

Java Tutorial : Java format and printf methods


Click here to watch in Youtube :
https://www.youtube.com/watch?v=B9T6PDXwXeE&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial : Java format and printf methods 
Java Tutorial : Java format and printf methods 
FormatNumericExample.java
public class FormatNumericExample
{

    public static void main(String[] args)
    {

        System.out.format("%s, %s", "Hello", "world");

        System.out.println("\n---------------------------");

        float floatVar = 90.8f;
        int intVar = 100;
        String stringVar = "Peter";

        System.out
                .format("The value of the float variable is "
                        + "%f, while the value of the integer variable is %d, "
                        + "and the string is %s", floatVar, intVar,
                        stringVar);

    }
}
Output
Hello, world
---------------------------
The value of the float variable is 90.800003, while the value of the integer variable is 100, and the string is Peter
PrintfNumericExample.java
public class PrintfNumericExample
{

    public static void main(String[] args)
    {

        System.out.printf("%s, %s", "Hello", "world");

        System.out.println("\n---------------------------");

        float floatVar = 90.8f;
        int intVar = 100;
        String stringVar = "Peter";

        System.out
                .printf("The value of the float variable is "
                        + "%f, while the value of the integer variable is %d, "
                        + "and the string is %s", floatVar, intVar,
                        stringVar);

    }
}
Output
Hello, world
---------------------------
The value of the float variable is 90.800003, while the value of the integer variable is 100, and the string is Peter
Click the below link to download the code:
https://sites.google.com/site/javaee4321/java/FormatDemo_format_App.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/FormatDemo_format_App

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/d0559102086f9677d57877fbba43556aca45fc19/BasicJava/FormatDemo_format_App/?at=master

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • No comments:

    Post a Comment