AmbitionBox

Discover Best Places to work in India

Java Programming

Java Programming Questions and Answers

Showing 1 - 10 of 37 questions

1

Which all lines are part of the output when the following code is compiled and run. Select the one correct answer.


public class test {
	public static void main(String args[]) {
	    for(int i = 0; i < 3; i++) {
		for(int j = 3; j <= 0; j--) {
		    if(i == j) continue;
		    System.out.println(i + " " + j);
		}
	    }
 	}
}

 

a

1 1

b

2 3

c

3 0

d

The program does not print anything

correct answer d
2

What happens when the following class is compiled and run. Select one correct answer.


public class test {
	public static void main(String args[]) {
		int x = 0, y = 1, z;
		if(x) 
		    z = 0;
		else
		    z = 1;

		if(y) 
		    z = 2;
		else
		    z = 3;
		System.out.println(z); 		
	}
}

 

a

The program prints 0

b

The program prints 1

c

The program prints 2

d

The program does not compile because of problems in the if statement.

correct answer d
3

What all gets printed when the following gets compiled and run. Select the two correct answers.


public class example {
	public static void main(String args[]) {
		int x = 0;
		if(x > 0) x = 1;

		switch(x) {
		case 1: System.out.println(1);
		case 0: System.out.println(0);
		case 2: System.out.println(2);
			break;
		case 3: System.out.println(3);
		default: System.out.println(4);
			break;
		}
	}
}

 

 

a

0

b

1

c

2

d

3

correct answer a,c
4

What is the result of compiling and running the following program. Select one correct answer.


public class test {
	public static void main(String args[]) {
		int i = -1;
		i = i >> 1;	 
 		System.out.println(i);
	}
}

 

 

a

63

b

-1

c

0

d

127

correct answer b
5

Which of the following are correct. Select all correct answers.

 

a

Java provides two operators to do left shift - << and <<<

b

>> is the zero fill right shift operator

c

>>> is the signed right shift operator

d

For positive numbers, results of operators >> and >>> are same

correct answer d
6

What gets displayed on the screen when the following program is compiled and run. Select the one correct answer.


public class test {
	public static void main(String args[]) {
		int x;

		x = -3 >> 1;
		x = x >>> 2;
		x = x << 1;
 		System.out.println(x);
	}
}

 

 

a

1

b

7

c

23

d

2147483646

correct answer d
7

What gets displayed on the screen when the following program is compiled and run. Select the one correct answer.


public class test {
	public static void main(String args[]) {
		int x, y;

		x = 5 >> 2;
		y = x >>> 2;
 		System.out.println(y);
	}
}

 

 

a

5

b

80

c

0

d

64

correct answer c
8

What gets displayed on the screen when the following program is compiled and run. Select the one correct answer.


public class test {
	public static void main(String args[]) {
		boolean x = false;
		int a;
		if(x) a = x ? 1: 2;
		else a = x ? 3: 4;
		System.out.println(a);
	}
}

 

 

a

1

b

2

c

3

d

4

correct answer d
9

What gets displayed on the screen when the following program is compiled and run. Select the one correct answer.


public class test {
	public static void main(String args[]) {
		boolean x = true;
		int a;
		if(x) a = x ? 1: 2;
		else a = x ? 3: 4;
		System.out.println(a);
	}
}

 

 

a

1

b

2

c

3

d

4

correct answer a
10

Which operator is used to perform bitwise exclusive or

 

a

&

b

^

c

|

d

~

correct answer a,b
Select a company to compare with

vs

Similar Companies