Java Operators (GATE - CS)

Tests Java operators including bit shift, arithmetic, Math functions, unary operators, and their interaction with switch statements

15 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

What is the output of the given java code?

public class HelloWorld
{
public static void main(String []args)
{
boolean i=1;
switch(Math.round(Math.hypot(114,123))) // Line 1
{
default : System.out.println("Default Case");
case 128<<6<<3 : System.out.println("Case 1");
case 9072/54 : System.out.println("Case 2");
case 128<<4<<2 : System.out.println("Case 3");
}
}
}

  1. Default Case Case 1 Case 2 Case 3
  2. Case 1Case 2Case 3
  3. Case 2Case 3
  4. Case 3
  5. Compilation Error
Question 2 Multiple Choice (Single Answer)

What is the output of the given java program?

public class HelloWorld
{
public static void main(String []args)
{
int i = 1024<<8<<3>>8>>3;
switch(i)
{
default : System.out.println("Default");
case 1048576/(34*32) : System.out.println("Case 1");
case 1073741824/(2*32*4*32*16*8) : System.out.println("Case 2");
case 1048576/(32*32) : System.out.println("Case 3");
}
}
}

  1. Default Case 1 Case 2 Case 3
  2. Case 1 Case 2 Case 3
  3. Case 2 Case 3
  4. Case 3
  5. Compiler Error
Question 3 Multiple Choice (Single Answer)

What is the output of the given java code?

public class HelloWorld
{
public void ret(int a, int b)
{
double res = Math.pow(a,b);
System.out.println(res);
}
public static void main(String []args)
{
HelloWorld h = new HelloWorld();
int i = (1048576>>8>>3>>4>>3);
int y = 1024>>4>>3;
h.ret(i,y);
}
}

  1. 25686.0
  2. 25656.0
  3. 65556.0
  4. 65536.0
  5. Compilation error
Question 4 Multiple Choice (Single Answer)

What is the output of the given java program?

public class HelloWorld
{
 public static void main(String []args)
{
 int i = 1024<<8<<3>>8>>3; switch(i)
 {
 default : System.out.
println("Default");
case 1048576/(34*32) : System.out.
println("Case 1");
case 1073741824/(2*32*4*32*16*8*2) : System.out.
println("Case 2");
case 1048576/(32*32) : System.out.
println("Case 3");
 }
 }
 }

  1. Default Case 1Case 2Case 3
  2. Case1Case 2Case 3
  3. Case 2Case 3
  4. Case 3
  5. Compiler Error
Question 5 Multiple Choice (Single Answer)

What is the output of the given java program?

public class HelloWorld
{
 public static void main(String []args)
{
 int i = 1048576>>8>>3>>8>>3;
switch(i++ - 1) // Line 1
{
case "-1" : System.out.
println("Case -1");
case "1" : System.out.
println("Case 1");
default : break;
case "0" : System.out.
println("Case 0");
 }
 }
 }

  1. Case -1Case 1Case 0
  2. Case -1Case 1
  3. Case 0
  4. Case 1
  5. Compiler error.
Question 6 Multiple Choice (Single Answer)

What is the output of the given java code?

public class HelloWorld
{
public static void main(String []args)
{
System.out.println( Math.round(Math.hypot(4+1,9-1)));
}
}

  1. 13
  2. 9
  3. 12
  4. 16
  5. 22
Question 7 Multiple Choice (Single Answer)

What is the output of the given Java Program?

public class HelloWorld
{
public static void main(String []args)
{
int i = 1048576>>8>>3>>8>>3;
switch(i++ - 1) // Line 1
{
case -1 : System.out.println("Case -1");
case 1 : System.out.println("Case 1");
default : break;
case 0 : System.out.println("Case 0");
}
}
}

  1. Case -1 Case 1
  2. Case -1Case 1Case 0
  3. Case 0
  4. No output
  5. Error at Line 1
Question 8 Multiple Choice (Single Answer)

What is the output of the given java code?

public class HelloWorld
{
public void ret(int a, int b)
{
double res = Math.pow(a,b);
System.out.println(res);
}
public static void main(String []args)
{
HelloWorld h = new HelloWorld();
int i = (1048576>>8>>3>>4>>3);
int y = 1024>>4>>3;
h.ret(i,y);
System.out.println(i^y);

  1. 65536.0 12
  2. 65536.0 16
  3. 25536.012
  4. 25536.012
  5. Compiler Error
Question 9 Multiple Choice (Single Answer)

What is the output of the given java code?

public class HelloWorld
{
public static void main(String []args)
{
int i;
switch(i) // Line 1
{
default : System.out.println("No Value");
case 0 : System.out.println("i is 0");
case 1 : System.out.println("i is 1");
}
}
}

  1. No Valuei is 0i is 1
  2. i is 0i is 1
  3. i is 1
  4. No output
  5. Compilation Error
Question 10 Multiple Choice (Single Answer)

What is the output of the given java program?

public class HelloWorld
{
public static void main(String []args)
{
int i = 1048576>>8>>3>>8>>3;
switch(1 + i++ - 1) // Line 1
{
case 0 : System.out.println(1024<<8<<3>>8>>3);
case -1 : System.out.println(1024<<2>>3<<2);
default : break;
case 1 : System.out.println(1024<<3<<8>>3>>3);
}

  1. 32768
  2. 10242048
  3. 2048
  4. No Output
  5. Error at Line 1
Question 11 Multiple Choice (Single Answer)

What is the output of the given java program?

public class HelloWorld
{
public static void main(String []args)
{
int i = (1048576>>8>>3>>8>>3) + + - + (1024<<8<<3>>8>>3);
switch(i) // Line 1
{
default : System.out.println("Good Bye");
case 1024 : System.out.println(1024<<8<<3>>8>>3);
case 512 : System.out.println(1024<<2>>3<<2);
case 1 : System.out.println(1024<<3<<8>>3>>3);
}
}
}

  1. Good Bye 1024 2048 32768
  2. 1024 2048 32768
  3. 2048 32768
  4. 32768
  5. Compilation error
Question 12 Multiple Choice (Single Answer)

What is the output of the given java program?

public class HelloWorld
{
public static void main(String []args)
{
int i= (int)Math.round(Math.hypot(114,123));
switch(i) // Line 1 { default : System.out.println("Default Case");
 case 128<<6<<3 : System.out.println("Case 1");
 case 9072/54 : System.out.
println("Case 2"); case 128<<4<<2 :
 System.out.println("Case 3");
 }
 }
 }

  1. Default CaseCase 1Case 2Case 3
  2. Case 1Case 2Case 3
  3. Case 2Case 3
  4. Case 3
  5. Compilation Error
Question 13 Multiple Choice (Single Answer)

What is the output of the given java program?

public class HelloWorld
{
 public static
void main(String []args)
{
 int i = (1048576>>8>>3>>8>>3) + + - + (1024<<8<<3>>8>>3);
 switch(i++) // Line 1 { case 1024 : System.out.
println("Hello"); case 1025 : System.out.
println("How r u?"); case 512 : System.out.
println("Bye"); case 513 : System.out.
println("Bye Bye"); default : System.out.
println("Good Bye");
 }
 }
 }

  1. HelloHow r u?Bye Bye ByeGood Bye
  2. How r u? Bye Bye Bye Good Bye
  3. Bye Bye ByeGood Bye
  4. Bye ByeGood Bye
  5. Good Bye
Question 14 Multiple Choice (Single Answer)

What is the output of the given java program?

public class HelloWorld
{
public static void main(String []args)
{
int i = 1024<<8<<3>>8>>3;
switch(i)
{
default : break;
case 1048576/(34*32) : System.out.println("Case 1");
case 1073741824/(2*32*4*32*16*8*2) : System.out.println("Case 2");
case 1048576/(32*30*4) : System.out.println("Case 3");
}
}
}

  1. Case 1Case 2Case 3
  2. Case 2 Case 3
  3. Case 3
  4. No output
  5. Compiler Error
Question 15 Multiple Choice (Single Answer)

What is the output of the given java code?

public class HelloWorld
{
 public static
void main(String []args)
{
 int i=1;
 if(i) switch(i++)
// Line 1 { default : System.out.println("No Value");
 case 0 : System.out.
println("i is 0");
 case 1 : System.out.
println("i is 1");
 case 2 : System.out.
println("i is 2");
 }
 }

  1. Valuei is 0i is 1i is 2
  2. i is 0i is 1i is 2
  3. i is 1i is 2
  4. i is 2
  5. Compilation Error