September 2005
Beginner
576 pages
13h 6m
English
You can put a value into 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 up a starting value for a variable upon its creation, use the equal sign (=). The following is an example of creating a floating-point variable called pi with the starting value of 3.14:
float 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 shown previously.
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:
Read now
Unlock full access