/Users/lyon/j4p/src/bookExamples/ch03Ops/Chapter3Ops.java

1    package bookExamples.ch03Ops; 
2     
3     
4    public class Chapter3Ops { 
5        public static void main(String args[]) { 
6            int x = 4, y = 2, z = 1; 
7            print("____________________________"); 
8            print("x = 4, y = 2, and z = 1" 
9                    + "\nso when you calculate " 
10                   + "x * (y + z)" 
11                   + "the result is " 
12                   + (x * (y + z))); 
13           print("x = 4, y = 2, and z = 1" 
14                   + "\nso when you calculate" 
15                   + " (x * y) + z the result is " 
16                   + ((x * y) + z)); 
17           int x1 = 0; 
18           print("____________________________"); 
19           print("if we call Math.cos(x) when x = 0 " 
20                   + "using the member" 
21                   + "selection\nwe can " 
22                   + "invoke method " 
23                   + "cos of the Math class, " 
24                   + "the result is " 
25                   + Math.cos(x1)); 
26           int x2 = 4, y1 = 2; 
27           print("____________________________"); 
28           print("if we call Math.pow(x,y) " 
29                   + "when x = 4 " 
30                   + "and y = 2 using the " 
31                   + "separation" 
32                   + "\nwe can invoke method " 
33                   + "pow of the Math class," 
34                   + "the result is " + Math.pow(x2, y1)); 
35           int x3 = 0; 
36           print("____________________________"); 
37           print("x = 0 but x++ = " 
38                   + x3++); 
39           print("after x++, x = " 
40                   + x3); 
41           int x4 = 0; 
42           print("____________________________"); 
43           print("x = 0 but x-- = " 
44                   + x4--); 
45           print("after x--, x = " 
46                   + x4); 
47           int x5 = 0; 
48           print("____________________________"); 
49           print("x = 0 but ++x = " 
50                   + ++x5); 
51           print("after ++x, x = " 
52                   + x5); 
53           int x6 = 0; 
54           print("____________________________"); 
55           print("x = 0 but --x = " 
56                   + --x6); 
57           print("after --x, x = " 
58                   + x6); 
59           int x19 = 4; 
60           print("____________________________"); 
61           print("x = 4 but +x = " 
62                   + (+x19)); 
63           int x18 = 4; 
64           print("____________________________"); 
65           print("x = 4 but -x = " 
66                   + (-x18)); 
67           int x17 = 4, y12 = 2; 
68           print("____________________________"); 
69           print("x = 4 and y = 2\nso x * y = " 
70                   + (x17 * y12)); 
71           int x16 = 4, y11 = 2; 
72           print("____________________________"); 
73           print("x = 4 and y = 2\nso x / y = " 
74                   + (x16 / y11)); 
75           int x15 = 4, y10 = 2; 
76           print("____________________________"); 
77           print("x = 4 and y = 2" 
78                   + "\nso x % y = " + (x15 % y10)); 
79           int x14 = 4, y9 = 2; 
80           print("____________________________"); 
81           print("x = 4 and y = 2" 
82                   + "\nso x + y = " 
83                   + (x14 + y9)); 
84           int x13 = 4, y8 = 2; 
85           print("____________________________"); 
86           print("x = 4 and y = 2" 
87                   + "\nso x - y = " 
88                   + (x13 - y8)); 
89           int x12 = 4, y7 = 2; 
90           print("____________________________"); 
91           print("x = 4, y = 2\nso x = y " 
92                   + "makes x equal to " 
93                   + (x12 = y7)); 
94           int x11 = 4, y6 = 2; 
95           print("____________________________"); 
96           print("x = 4 and y = 2\nso x += y makes" 
97                   + "x equal to " + (x11 += y6)); 
98           int x10 = 4, y5 = 2; 
99           print("____________________________"); 
100          print("x = 4 and y = 2" 
101                  + "\nso x -= y " 
102                  + "makes x equal to " 
103                  + (x10 -= y5)); 
104          int x9 = 4, y4 = 2; 
105          print("____________________________"); 
106          print("x = 4 and y = 2" 
107                  + "\nso x *= y makes " 
108                  + "x equal to " 
109                  + (x9 *= y4)); 
110          int x8 = 4, y3 = 2; 
111          print("____________________________"); 
112          print("x = 4 and y = 2" 
113                  + "\nso x /= y makes x equal to " 
114                  + (x8 /= y3)); 
115          int x7 = 4, y2 = 2; 
116          print("____________________________"); 
117          print("x = 4 and y = 2\n" 
118                  + "so x %= y makes x equal to " 
119                  + (x7 %= y2)); 
120      } 
121   
122      public static void print(Object o) { 
123          System.out.println(o); 
124      } 
125  } 
126