Operators and Control Statements
a) Numeric
b) Boolean
c) Characters
d) Both Numeric & Characters
a) Integers
b) Floating – point numbers
c) Both Integers and floating – point numbers.
d) None of the mentioned
class increment {
public static void main(String args[])
{
double var1 = 1 + 5;
double var2 = var1 / 4;
int var3 = 1 + 5;
int var4 = var3 / 4;
System.out.print(var2 + " " + var4);
}
}
a) 1 1
b) 0 1
c) 1.5 1
d) 1.5 1.0
class Output {
public static void main(String args[])
{
int x , y;
x = 10;
x++;
--x;
y = x++;
System.out.println(x + " " + y);
}
}
a) 11 11
b) 10 10
c) 11 10
d) 10 11
a) &
b) &=
c) |=
d) <=
a) The left shift operator, <<, shifts all of the bite in a value to the left specified number of times. b) The right shift operator, >>, shifts all of the bite in a value to the right specified number of times.
c) The left shift operator can be used as an alternative to multiplying by 2.
d) The right shift operator automatically fills the higher order bits with 0.
class bitwise_operator {
public static void main(String args[])
{
int var1 = 42;
int var2 = ~var1;
System.out.print(var1 + " " + var2);
}
}
a) 42 42
b) 43 43
c) 42 -43
d) 42 43
class bitwise_operator {
public static void main(String args[])
{
int a = 3;
int b = 6;
int c = a | b;
int d = a & b;
System.out.println(c + " " + d);
}
}
a) 7 2
b) 7 7
c) 7 5
d) 5 2
class leftshift_operator {
public static void main(String args[])
{
byte x = 64;
int i;
byte y;
i = x << 2;
y = (byte) (x << 2)
System.out.print(i + " " + y);
}
}
a) 0 64
b) 64 0
c) 0 256
d) 256 0
class rightshift_operator {
public static void main(String args[])
{
int x;
x = 10;
x = x >> 1;
System.out.println(x);
}
}
a) 10
b) 5
c) 2
d) 20
class Output {
public static void main(String args[])
{
int a = 1;
int b = 2;
int c = 3;
a |= 4;
b >>= 1;
c <<= 1;
a ^= c;
System.out.println(a + " " + b + " " + c);
}
}
a) 3 1 6
b) 2 2 3
c) 2 3 4
d) 3 3 6
a) Integer
b) Boolean
c) Characters
d) Double
a) !
b) |
c) &
d) &&
a) true and false are numeric values 1 and 0.
b) true and false are numeric values 0 and 1.
c) true is any non zero value and false is 0.
d) true and false are non numeric values.
class Relational_operator {
public static void main(String args[])
{
int var1 = 5;
int var2 = 6;
System.out.print(var1 > var2);
}
}
a) 1
b) 0
c) true
d) false
class bool_operator {
public static void main(String args[])
{
boolean a = true;
boolean b = !true;
boolean c = a | b;
boolean d = a & b;
boolean e = d ? b : c;
System.out.println(d + " " + e);
}
}
a) false false
b) true ture
c) true false
d) false true
class ternary_operator {
public static void main(String args[])
{
int x = 3;
int y = ~ x;
int z;
z = x > y ? x : y;
System.out.print(z);
}
}
a) 0
b) 1
c) 3
d) -4
class Output {
public static void main(String args[])
{
int x , y = 1;
x = 10;
if (x != 10 && x / 0 == 0)
System.out.println(y);
else
System.out.println(++y);
}
}
a) 1
b) 2
c) Runtime error owing to division by zero in if condition.
d) Unpredictable behavior of program.
class Output {
public static void main(String args[])
{
boolean a = true;
boolean b = false;
boolean c = a ^ b;
System.out.println(!c);
}
}
a) 0
b) 1
c) false
d) true
a) ()
b) ++
c) *
d) >>
expression1 ? expression2 : expression3
a) Integer
b) Floating – point numbers
c) Boolean
d) None of the mentioned
int x, y, z;
x = 0;
y = 1;
x = y = z = 8;
a) 0
b) 1
c) 9
d) 8
1. &
2. ^
3. ?:
a) 1 -> 2 -> 3
b) 2 -> 1 -> 3
c) 3 -> 2 -> 1
d) 2 -> 3 -> 1
a) Equal to operator has least precedence.
b) Brackets () have highest precedence.
c) Division operator, /, has higher precedence than multiplication operator.
d) Addition operator, +, and subtraction operator have equal precedence.
class operators {
public static void main(String args[])
{
int var1 = 5;
int var2 = 6;
int var3;
var3 = ++ var2 * var1 / var2 + var2;
System.out.print(var3);
}
}
a) 10
b) 11
c) 12
d) 56
class operators {
public static void main(String args[])
{
int x = 8;
System.out.println(++x * 3 + " " + x);
}
}
a) 24 8
b) 24 9
c) 27 8
d) 27 9
class ternary_operator {
public static void main(String args[])
{
int x = 3;
int y = ~ x;
int z;
z = x > y ? x : y;
System.out.print(z);
}
}
a) 0
b) 1
c) 3
d) -4
1. a | 4 + c >> b & 7;
2. (a | ((( 4 * c ) >> b ) & 7 ))
a) 1 will give better performance as it has no parentheses.
b) 2 will give better performance as it has parentheses.
c) Both 1 & 2 will give equal performance.
d) Dependent on the computer system.
class Output {
public static void main(String args[])
{
int x , y = 1;
x = 10;
if (x != 10 && x / 0 == 0)
System.out.println(y);
else
System.out.println(++y);
}
}
a) 1
b) 2
c) Runtime error owing to division by zero in if condition.
d) Unpredictable behavior of program.
a) if()
b) for()
c) continue
d) break
a) break
b) return
c) exit
d) continue
class selection_statements {
public static void main(String args[])
{
int var1 = 5;
int var2 = 6;
if ((var2 = 1) == var1)
System.out.print(var2);
else
System.out.print(++var2);
}
}
a) 1
b) 2
c) 3
d) 4
class comma_operator {
public static void main(String args[])
{
int sum = 0;
for (int i = 0, j = 0; i < 5 & j < 5; ++i, j = i + 1)
sum += i;
System.out.println(sum);
}
}
a) 5
b) 6
c) 14
d) compilation error
class jump_statments {
public static void main(String args[])
{
int x = 2;
int y = 0;
for ( ; y < 10; ++y) {
if (y % x == 0)
continue;
else if (y == 8)
break;
else
System.out.print(y + " ");
}
}
}
a) 1 3 5 7
b) 2 4 6 8
c) 1 3 5 7 9
d) 1 2 3 4 5 6 7 8 9
class Output {
public static void main(String args[])
{
int a = 5;
int b = 10;
first: {
second: {
third: {
if (a == b >> 1)
break second;
}
System.out.println(a);
}
System.out.println(b);
}
}
}
a) 5 10
b) 10 5
c) 5
d) 10
post a comment