Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Assignment operator tMyn1 The Assignment Operator The result of a calculation can be stored in a variable using the assignment operator =. Because.

Similar presentations


Presentation on theme: "The Assignment operator tMyn1 The Assignment Operator The result of a calculation can be stored in a variable using the assignment operator =. Because."— Presentation transcript:

1 The Assignment operator tMyn1 The Assignment Operator The result of a calculation can be stored in a variable using the assignment operator =. Because the assignment operation first evaluates the right hand side and then stores the result in the variable on the left, we can write a statement like this: apples=apples*2;

2 The Assignment operator tMyn2 Assuming the variable is of type int, the following three statements all have exactly the same effect: count=count+1; count+=1; ++count; The increment operator ++ was written in front of the variable. This is called the prefix form. The increment (decrement) operator can also be written after the variable to which it applies.

3 The Assignment operator tMyn3 This is the postfix form, and the effect is slightly different. For example total=count++ + 6; is equivalent to this: total=count+6; ++count; Keep it as simple as possible!

4 The Assignment operator tMyn4 package assignmentop; public class Main { public static void main(String[] args) { int atTheBeginning=1; System.out.println("At the beginning: "+atTheBeginning++); System.out.println("Now it is "+atTheBeginning); System.out.println("Finally we have "+ ++atTheBeginning); } run: At the beginning: 1 Now it is 2 Finally we have 3 BUILD SUCCESSFUL (total time: 0 seconds)


Download ppt "The Assignment operator tMyn1 The Assignment Operator The result of a calculation can be stored in a variable using the assignment operator =. Because."

Similar presentations


Ads by Google