Difference Between System.out.print And System.out.prinln In Java

Here we will Differentiate Between System.out.print And System.out.prinln In Java where System.out.print is used for printing the output on the console whereas System.out.println is also used for printing the output n console but it passes the cursor to the next line just after printing the output.

System.out.print is used when we know that printed output is not self sufficient and it required some other outputs also for self explanations.

System.out.print

System.out.print

It is a way to print the output on the console without passing the control to the next line after printing value and if we use multiple System.out.print one after another then answers of all of them will be printed one after another in the same line and all the answers will be concatenated at the tail of one.

Let’s understand it with some examples

import java.io.*;

class GFG {
    public static void main(String[] args)
    {
        System.out.println("Welcome to JAVA (1st line)");
        
        // this print statement will be printed in a new line.
        System.out.print("Welcome to my world of Java (2nd line) ");
        
        // this print statement will be printed in the same line.
        System.out.print("Hello This is Prakhar (2nd line)");
    }
}

The output of it will be

Welcome to JAVA (1st line)

Welcome to my world of Java (2nd line) Hello This is Prakhar (2nd line)

As first line will be printed as we have used ln in it so it passes the cursor to the next line just after printing the values whereas ln is not there in the second line so the third line will be printed just after the second line and the cursor will be on the same line and third output will also be printed just after what was printed earlier.

System.out.println

As we know it is used for passing the cursor to the next line just after printing the output which needs to be printed So, for example, we can refer to the previous example where it is well explained.

Learn more about System.out.print and System.out.println at: Printing Outputs in different ways

And also have a look at Java Tutorials By Prakhar YadavTo to learn more about java problems and solutions also visit How To Reverse A String In Python? for learning more about python and other programing languages.

Leave a Comment

%d bloggers like this: