Answer 36
Listing 5 . Listing for Answer 36. |
---|
/*File SampProg07.java from module 22
Copyright 1997, R.G.BaldwinWithout reviewing the following solution, write a Java
application that clearly illustrates the difference betweenthe prefix and the postfix versions of the increment
operator.Provide a termination message that displays your name.
*********************************************************/class SampProg07{
static public void main(String[]args){
int x = 3;int y = 3;
int z = 10;System.out.println("Prefix version gives "
+ (z + ++x));System.out.println("Postfix version gives "
+ (z + y++));System.out.println("Terminating, Dick Baldwin");
}//end main}//end class SampProg07 |
Answer 35
Java supports the following list of shortcut assignment operators. These operators allow you to perform an assignment and another operation with asingle operator.
+=
-=*=
/=%=&=
|=^=<<=>>=>>>=
For example, the two statements that follow perform the same operation.
- x += y;
- x = x + y;
The behavior of each of the shortcut assignment operators follows this same pattern.
Answer 34
True.
Answer 33
The assignment operator is a binary operator.
Answer 32
True.
Answer 31
The answer for the bitwise exclusive or is:
- 11 1 xor 1 produces 0
- 10 1 xor 0 produces 1
- 01 0 xor 1 produces 1
- 00 0 xor 0 produces 0
Answer 30
The answer for the bitwise inclusive or is:
- 11 1 or 1 produces 1
- 10 1 or 0 produces 1
- 01 0 or 1 produces 1
- 00 0 or 0 produces 0
Answer 29
The answer for the bitwise and is:
- 11 1 and 1 produces 1
- 10 1 and 0 produces 0
- 01 0 and 1 produces 0
- 00 0 and 0 produces 0
Answer 28
True: Bits shifted off the right end are lost.
Answer 27
False: In Java, the signed right shift operation populates the vacated bits with the sign bit, while the left shift and the unsigned right shift populate the vacated bits with zeros.
Answer 26
The following table shows the seven bitwise operators supported by Java.
Operator Typical Use Operation>>OpLeft>>Dist Shift bits of OpLeft right by
Dist bits (signed)<<OpLeft<<Dist Shift bits of OpLeft left by
Dist bits>>>OpLeft>>>Dist Shift bits of OpLeft right
by Dist bits (unsigned)&OpLeft&OpRight Bitwise and of the two
operands| OpLeft | OpRight Bitwise
Answer 25
The bitwise and operator and the bitwise inclusive or operator are shown below.
&bitwise and
| bitwise inclusive or
Answer 24
An important characteristic of the behavior of the logical and operator and the logical or operator in Java is that the expressions containing them are evaluated from left to right. The evaluation of the expression is. terminated as soon as the result of evaluatingthe expression can be determined. For example, in the expression given in Question 24 , if the variable a is less than the variable b , there is no need to evaluate the right operand of the || operator to determine the value of the entire expression. Therefore, evaluation will terminate as soon as it isdetermined that a is less than b .