Basic Operators
- What is the output of this program?
public class Bitwise_Operator
{
public static void main(String args[])
{
int p = 8;
int q = 8;
int r = p | q;
int s = p & q;
System.out.println(r + " " + s);
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
And operator produces 1 bit if both operand are 1. Or operator produces 1 bit if any bit of the two operands in 1.
output: 8 8
- What is the output of this program?
public class RightShift_Operator
{
public static void main(String args[])
{
int a;
a = 100;
a = a >> 1;
System.out.println(a);
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: E
Right shift operator, >>, devides the value by 2.
output: 50
- What is the output of this program?
public class LeftShift_Operator
{
public static void main(String args[])
{
byte A = 65;
int i;
byte b;
i = A << 2;
b = (byte) (A << 2);
System.out.print(i + " " + b);
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
output: 260 4
- What is the output of this program?
public class Output
{
public static void main(String args[])
{
int p = 5;
int q = 7;
int r;
int s;
r = ++q;
s = p++;
r++;
q++;
++p;
System.out.println(p + " " + q + " " + r);
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Output: 7 9 9
- What is the output of this program?
public class Bitwise_Operator
{
public static void main(String args[])
{
int num1 = 30;
int num2 = ~num1;
System.out.print(num1 + " " + num2);
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Unary not operator, ~, inverts all of the bits of its operand. 30 in binary is 00011110 in using ~ operator on num1 and assigning it to num2 we get inverted value of 30 i:e 11100001 which is -31 in decimal.
output: 30 -31