println Statement Example in Java

Write an Example Program to print value of different data types using println() function

Hello World

10

10.20

true

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);


}

}


Output

println Statement Example in Java Output

Program Explanation

println function is method of class PrintStream. out is a instance of PrintStream Class and also the Data member of System class lies in java.lang package. print() method is overloaded method which prints all the datatypes. The following are the overloaded print() methods:

println(String s)

println(boolean b)

println(char c)

println(double d)

println(float f)

println(long l)

println(int i)

println(object obj)


Comments