Printing Variables

2 min read ·

Printing variables in Java allows you to display stored data such as numbers, text, and boolean values. Java can directly print variables of different data types using output statements.

Printing Integer Variables

Integer values can be printed directly without any special formatting.
The value stored in the variable is displayed as output.

Printing Decimal Values

Java supports decimal numbers using data types like double and float.
Decimal values are printed exactly as stored.

Printing String Variables

Text values are stored using the String data type.
Strings are printed without double quotes in the output.

Printing Character Variables

Single characters use the char data type.
Characters are written using single quotes but printed without them.

Printing Boolean Values

Boolean variables store either true or false.
Boolean values are printed as true or false.

Printing Multiple Variables

You can print multiple variables using separate output statements.
Each variable is printed on a new line.

Common Mistakes While Printing Variables

Using double quotes around variable names Trying to print variables without declaring them Writing output statements outside the main method
Caution

Writing variable names inside double quotes will print the text, not the variable value.


Why Printing Variables Is Important

Printing variables helps you: Understand how data flows in a program Check if values are stored correctly Debug logic errors easily
Goal Achieved

You can now print variable values of different data types correctly in Java.