Q 31- Using the symbols 1 and 0 construct a truth table showing the four possible combinations of 1 and 0. Using a 1 or a 0, show the result of the bitwise inclusive or operation on these four
combinations on these four combinations of 1 and 0.
A - The answer for the inclusive or is:
1 or 1 produces 1
1 or 0 produces 1
0 or 1 produces 1
0 or 0 produces 0
combinations on these four combinations of 1 and 0.
A - The answer for the inclusive or is:
1 or 1 produces 1
1 or 0 produces 1
0 or 1 produces 1
0 or 0 produces 0
combinations on these four combinations of 1 and 0.
A - The answer for the exclusive or is:
1 xor 1 produces 0
1 xor 0 produces 1
0 xor 1 produces 1
0 xor 0 produces 0
A - True.
A - The assignment operator is a binary operator.
A - True.
A - Java supports the following list of shortcut assignment operators. These operators allow you to perform an assignment and another operation with a single operator. += -= *= /= %= &= |= ^= <<= >>= >>>=
For example, the two statements which follow perform the same operation.
x += y; x = x + y;
The behavior of all the shortcut assignment operators follows this same pattern.
class prog3{
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++));
}//end main
}//end class
class Prog4 { //define the controlling class
public static void main(String[] args){ //define main method
System.out.println("The relational 6<5 is " + (6<5 ) );
System.out.println("The relational 6>5 is " + (6>5 ) );
System.out.println("The relational 5>=5 is " + (5>=5 ) );
System.out.println("The relational 5<=5 is " + (5<=5 ) );
System.out.println("The relational 6==5 is " + (6==5 ) );
System.out.println("The relational 6!=5 is " + (6!=5 ) );
}//end main
}//End prog4 class. Note no semicolon required
class prg5 { //define the controlling class
public static void main(String[] args){ //define main method
System.out.println("true and true is " + (true && true) );
System.out.println("true and false is " + (true && false) );
System.out.println("true or true is " + (true || true) );
System.out.println("true or false is " + (true || false) );
System.out.println("false or false is " + (false || false) );
System.out.println("not true is " + (! true) );
System.out.println("not false is " + (! false) );
}//end main
}
A - Java does not support a constant type. However, in Java, it is possible to achieve the same result by declaring and initializing a variable and making it final.
A - The syntax for creating a named constant in Java is as follows: final float PI = 3.14159;
A - you can control the order of evaluation by the use of parentheses.
A - The operation of a loop normally involves the following three actions in addition to executing the code in the body of the loop:
Initialize a control variable.
Test the control variable in a conditional expression.
Update the control variable.
No comments:
Post a Comment