Print and println difference with Example

Write an Example Program to differentiate print() and println()

Try your Solution

Strongly recommended to Solve it on your own, Don't directly go to the solution given below.

public class Hello { public static void main(String args[]) { //Write your code here } }

Program or Solution

				
				
					

class Program

{

public static void main(String args[])

{

//variable declaration and definition

int num = 10;

double num_f = 12.5;

char ch = 'D';

String name = "Decode";

boolean b = true;

String s = "true";


//printing using println statement

System.out.println(num);

System.out.println(num_f);

System.out.println(ch);

System.out.println(name);

System.out.println(b);

System.out.println(s);


//printing using print statement

System.out.print(num);

System.out.print(num_f);

System.out.print(ch);

System.out.print(name);

System.out.print(b);

System.out.print(s);


}

}


Output

Print and println difference with Example Output

Program Explanation

print() prints the given value and makes the cursor to stay back at end of the same line.

println() prints the given value and moves the cursor to next line.

print() and println() are belongs to the same class PrintStream

Comments