Java The Complete Reference, Seventh Edition
byte b = (byte) 0xf1; System.out.println("b = 0x" + hex[(b >> 4) & 0x0f] + hex[b & 0x0f]); } } Here is the output ...
Chapter 4: Operators 69 System.out.println(" b = 0x" hex[(b >> 4) & 0x0f] + hex[b & 0x0f]); System.out.println(" ...
70 Part I: The Java Language c <<= 1; a ^= c; System.out.println("a = " + a); System.out.println("b = " + b); System.out.p ...
int done; // ... if(!done) ... // Valid in C/C++ if(done) ... // but not in Java. In Java, these statements must be written like ...
Here is a program that is almost the same as theBitLogicexample shown earlier, but it operates onbooleanlogical values instead o ...
Since the short-circuit form of AND (&&) is used, there is no risk of causing a run-time exception whendenomis zero. If ...
74 Part I: The Java Language When Java evaluates this assignment expression, it first looks at the expression to theleftof the q ...
Chapter 4: Operators 75 However, if you want to first shiftaright bybpositions and then add 3 to that result, you will need to p ...
This page intentionally left blank ...
5 Control Statements 5 Control Statements A programming language usescontrolstatements to cause the flow of execution to advance ...
78 Part I: The Java Language Here, ifais less thanb, thenais set to zero. Otherwise,bis set to zero. In no case are they both se ...
Chapter 5: Control Statements 79 if (bytesAvailable > 0) { ProcessData(); bytesAvailable -= n; } else { waitForMoreData(); by ...
80 Part I: The Java Language lastelsestatement is performed. If there is no finalelseand all other conditions arefalse, then no ...
Chapter 5: Control Statements 81 // statement sequence break; default: // default statement sequence } Theexpressionmust be of t ...
82 Part I: The Java Language As you can see, each time through the loop, the statements associated with thecaseconstant that mat ...
Chapter 5: Control Statements 83 While the preceding example is, of course, contrived for the sake of illustration, omitting the ...
case 1: // no conflicts with outer switch System.out.println("target is one"); break; } break; case 2: // ... Here, thecase 1:st ...
Here is awhileloop that counts down from 10, printing exactly ten lines of “tick”: // Demonstrate the while loop. class While { ...
86 Part I: The Java Language System.out.println("Midpoint is " + i); } } This program finds the midpoint betweeniandj. It genera ...
do { System.out.println("tick " + n); } while(--n > 0); In this example, the expression(– –n > 0)combines the decrement of ...
«
1
2
3
4
5
6
7
8
9
10
»
Free download pdf