How to print different type of values in Java?

Here, we will learn how to print different type of values using Java program? In this program, we will declare and define different variables with values and print them.

Given different type of values and we have to print them on output screen.

In this program, we are going to declare and define some of the different type of variables and then will print them using System.out.println() method.

Consider the program:

class j2{ 
	public static void main(String args[]) 
	{ 
		int num; 
		float b; 
		char c; 
		String s; 
		
		//integer
		num     =       100; 
		//float
		b       =       1.234f; 
		//character
		c       =       'A'; 
		//string
		s       =       "Hello Java"; 

		System.out.println("Value of num: "+num);
		System.out.println("Value of b: "+b);
		System.out.println("Value of c: "+c);
		System.out.println("Value of s: "+s); 
	} 
}

Output

Value of num: 100 
Value of b: 1.234 
Value of c: A 
Value of s: Hello Java

Java Basic Programs »



Related Programs




Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.