![]() |
![]() |
![]() |
![]() |
![]() |
|
To change the value of a variable, you use the
assignment operator, =. Three assignment statements appear
in the following program:
public class Demonstrate {
public static void main (String argv[]) {
int result, script = 6, acting = 9, direction = 8;
result = script;
result = result + acting;
result = result + direction;
System.out.print("The rating of the movie is ");
System.out.println(result);
}
}
Of course, this program is a bit awkwardthe only reason to split the computation into three separate statements is to demonstrate that a variable can be assigned and then reassigned.