Java Variables
Displaying variables is a common usage for the println() function.
Use the + symbol to merge text with a variable:
String name = "John";
System.out.println("Hello " + name);
Additionally, you can add a variable to another variable by using the + symbol:
String firstName = "John ";
String lastName = "Doe";
String fullName = firstName + lastName;
System.out.println(fullName);
The + symbol functions as a mathematical operator for numeric values (note that we are using int (integer) variables here):
int x = 5;
int y = 6;
System.out.println(x + y); // Print the value of x + y
From the above example, you may anticipate:
CodingAsk.com is designed for learning and practice. Examples may be made simpler to aid understanding. Tutorials, references, and examples are regularly checked for mistakes, but we cannot guarantee complete accuracy. By using CodingAsk.com, you agree to our terms of use, cookie, and privacy policy.
Copyright 2010-2024 by Refsnes Data. All Rights Reserved.