Storing Information in Variables
You can store a value in a variable at the same time that you create the variable in a Java program. You also can put a value in the variable at any time later in the program.
To set a starting value for a variable upon its creation, use the equal sign (=). Here’s an example of creating a double floating-point variable called pi with the starting value of 3.14:
double pi = 3.14;
All variables that store numbers can be set up in a similar fashion. If you’re setting up a character or a string variable, quotation marks must be placed around the value as described earlier in this hour.
You also can set one variable equal to the value of another variable if they both are of the same type. Consider the following example: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access