Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

How to Use the print() Function in Java

/* For this function, let me use the example I have used
just now. You should be able to see the difference right away:
*/


public class Main{
    public static void main(String[] args) {
        System.out.print("Hello World!");
        System.out.print("Welcome to freeCodeCamp");
    }
}


/* Here, you see that I used print instead of using println
like I did earlier. The print doesn't add the additional 

(new line character) after executing the task in it.
This means that you will not get any new line after executing
any print statement like above.
*/

// The output will be like this:


// Hello World!Welcome to freeCodeCamp


/* If you want, then you can also solve this issue using 

like below:
*/


public class Main{
    public static void main(String[] args) {
        System.out.print("Hello World!
");
        System.out.print("Welcome to freeCodeCamp");
    }
}


/* This time, the 
 will work as the new line character and
you will get the second string in a new line.
The output is like below:
*/


// Hello World!
// Welcome to freeCodeCamp


/* You can also print the two strings using only one print
statement like below:
*/


public class Main{
    public static void main(String[] args) {
        System.out.print("Hello World!
Welcome to freeCodeCamp");
    }
}


// The output will be the same this time:


// Hello World!
// Welcome to freeCodeCamp
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #How #Use #Function #Java
ADD COMMENT
Topic
Name
1+3 =