File tree Expand file tree Collapse file tree
src/lesson2OperatorsandFlowControl Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package lesson2OperatorsandFlowControl ;
2+
3+ public class AssignmentOperators {
4+ public static void main (String [] args ) {
5+ int num ;
6+ String name ;
7+
8+ num = 15 ;
9+ name = "J" ;
10+
11+ System .out .println ("num is assigned: " + num );
12+ System .out .println ("name is assigned: " + name );
13+
14+ /* += operator - operates by adding current value of variable on the left to the value on right and then assign result
15+ * to the operand on left
16+ */
17+ int num1 = 20 , num2 = 1 ; // the three lines here are necessary for declaring variables to use each operator
18+ System .out .println ("num1 = " + num1 );
19+ System .out .println ("num2 = " + num2 );
20+
21+ num1 += num2 ; // Adds and assigns values
22+
23+ System .out .println ("num1 = " + num1 ); // displays assigned values
24+
25+ // -= operator subtracts variable's value on right from current value on the left and then assigns the result to operand on left
26+
27+ num1 -= num2 ;
28+
29+ System .out .println ("num1 = " + num1 );
30+
31+ // *= operator multiplies current variable value on the left to the value on the right, and assign result to the left operand
32+
33+ num1 *= num2 ;
34+
35+ System .out .println ("num1 = " + num1 );
36+
37+ // /= operator divides current variable value on the left by the value on the right, then assigns quotient to left operand
38+
39+ num1 *= num2 ;
40+
41+ System .out .println ("num1 = " + num1 );
42+
43+ // %= operator divides current variable value on the left by the value, then assigns remainder to the left operand
44+
45+ num1 %= num2 ;
46+
47+ System .out .println ("num1 = " + num1 );
48+
49+ }
50+
51+ }
You can’t perform that action at this time.
0 commit comments