7/15/10

Basic Printing

Here is a code example of basic printing with JAVA.

public static void main ( String[] args)
{
     System.out.print (" Hello World. ");
     System.out.printf (" I am printing this line. ");
}



Output:

 Hello World.  I am printing this line.

As you would notice the output is not with correct spacing.
Revising the code above to:


public static void main ( String[] args)
{
     System.out.print ("Hello World. \n");
     System.out.printf ("I am printing this line. ");
}   

Output:

Hello World.
I am printing this line.

\n is used to print a new line to the output.


0 comments:

Post a Comment

 
Powered by Blogger