Vous êtes sur la page 1sur 14

[30] What will be the output of the code snippet given below?

public class Main { public static void main ( String[ ] args ) { int i, j, k ; for ( i = 0 ; i <= 3 ; i++ ) { for( j = 0 ; j <= 3 - i ; j++ ) System.out.print ( "*" ) ; for ( k = 0 ; k <= i ; k++ ) System.out.print ( i ) ; } } } Choice a **********0123 Choice b **********0112223333 Choice c ****0***11**222*3333 Choice d 0112223333********** [29] What will be the output of the code snippet given below? public class Main { public static void main ( String[ ] args ) { int x = 5, y = 6, z = 7, w = 8, p = x++ * y++ / z++ * ++w, q = x++ * ++y * ++z / p * w++, r = x-* y-- * --z / --q ; System.out.println ( x + " " + y + " " + z + " " + w + " " + p + " " + q + " " + r ) ; } } Choice a . 6 7 8 10 36 107 4 Choice b

5 6 7 8 36 107 4 Choice c 6 7 8 10 37 108 5 Choice d 5 6 7 8 37 108 5 [28] Which of the following statement is correct about the code snippet given below? public class Main { public static void main ( String[ ] args ) { int bar = 1 ; { int bar = 2 ; System.out.println ( bar ) ; } } } Choice a The code reports an error. . Choice b The code causes an exception Choice c The code gives an output as 1. Choice d The code gives an output as 2. [27] What will be the output of the code snippet given below? public class Main { public static void main ( String[ ] args ) { int x ; x = 10 ; if ( x == 10 ) {

int y = 20 ; System.out.println ( x + " " + y ) ; x=y*2; } System.out.println ( x ) ; } } Choice a 10 20 10 Choice b .. 10 20 40 Choice c 40 20 40 Choice d 20 20 10 [26] What will be the output of the code snippet given below? public class Main { public static void main ( String[ ] args ) { double pi, r, a ; r = 10.8 ; pi = 3.1416 ; a = pi * r * r ; System.out.println ( a ) ; } } Choice a 366.436224 Choice b 366.44 Choice c

366.43 Choice d 366.430000 [25] Which of the following statement is correct about the code snippet given below? public class Main { public static void main ( String[ ] args ) { int i = 400 * 400 / 400 ; if ( i == 400 ) System.out.println ( "In if" ) ; else System.out.println ( "In else" ) ; } } Choice a The code reports an error. Choice b The code causes an exception Choice c . The code gives an output as In if. Choice d The code gives an output as In else

[24] What will be the output of the code snippet given below? public class Main { public static void main ( String[ ] args ) { double a = 3.0, b = 4.0 ; double c = Math.sqrt ( a * a + b * b ) ; System.out.println ( c ) ; } }

Choice a 5.00 Choice b 5 Choice c .. 5.0 Choice d 5.000000 [23] What will be the output of the code snippet given below? public class Main { public static void main ( String[ ] args ) { int x = 10, y = 20 ; boolean a, b ; a=!(x>y); b=x<y; System.out.print ( a + " " + b ) ; } } Choice a 01 Choice b false true Choice c 11 Choice d . true true [22] Which of the following statements are correct? I. The relational operators determine the relationship that one operand has to the other. II. The relational operators determine equality and ordering.

Choice a Only I is correct. Choice b Only II is correct. Choice c .. Both I and II are correct. Choice d Both I and II are incorrect.

[21] Which of the following statements are correct? I. In Java, the else clause is optional. II. if condition is any expression that returns any character value. Choice a . Only I is correct. Choice b Only II is correct. Choice c Both I and II are correct. Choice d Both I and II are incorrect.

[20] Which of the following statements are correct? I. For each left shift, the high-order bit is shifted out and lost and a zero is brought in on the left. II. When a left shift is applied to an int operand, bits are lost once they are shifted past bit position 63. Choice a Only I is correct. Choice b Only II is correct. Choice c Both I and II are correct.

Choice d .. Both I and II are incorrect.

[19] Which of the following selection statements are supported by Java? I. if II. switch III. Macro Choice a .. Only I and II Choice b Only I and III Choice c Only II and III Choice d I, II and III

[18] Which of the following statements are correct? I. Nested if else statements are not allowed in java. II. if statements are executed from top to down. Choice a Only I is correct. Choice b .. Only II is correct. Choice c Both I and II are correct. Choice d Both I and II are incorrect.

[17] Which of the following statements are correct? I. if statement is Javas conditional branch statement. II. if statement is used to route program execution through two different paths. Choice a Only I is correct.

Choice b Only II is correct. Choice c Both I and II are correct. Choice d Both I and II are incorrect.

[16] Which of the following statements are correct? I. When the division operator is applied to an integer type, there will be a fractional component attached to the result. II. In Java, modulus operator cannot be applied to floating-point types. Choice a Only I is correct. Choice b Only II is correct. Choice c Both I and II are correct. Choice d .. Both I and II are incorrect.

[15] Which of the following statements are correct? I. In Java, an integer literal cannot be assigned to a long variable. II. To specify a long literal, user needs to explicitly tell the compiler that the literal value is of type long by appending an upper or lowercase L to the literal. Choice a Only I is correct. Choice b . Only II is correct. Choice c Both I and II are correct. Choice d Both I and II are incorrect.

[14] Which of the following statements are correct? I. The type float specifies a single-precision value that uses 64 bits of storage. II. Java uses Unicode to represent characters. Choice a Only I is correct. Choice b .. Only II is correct. Choice c Both I and II are correct. Choice d Both I and II are incorrect.

[13] Which of the following statements are correct? I. boolean data type is returned by all relational operators. II. When a boolean value is output by println( ), 1 or 0 gets displayed. Choice a Only I is correct. Choice b Only II is correct. Choice c Both I and II are correct. Choice d Both I and II are incorrect.

[12] Which of the following statements are correct? I. Floating-point numbers are used when evaluating expressions that require fractional precision. II. Java implements the standard set of floating-point types and operators. Choice a Only I is correct. Choice b Only II is correct.

Choice c . Both I and II are correct. Choice d Both I and II are incorrect.

[11] Which of the following statements are correct? I. The Java compiler checks all expressions and parameters to ensure that the types are compatible. II. In Java, we can assign a floating-point value to an integer. Choice a Only I is correct. Choice b Only II is correct. Choice c Both I and II are correct. Choice d Both I and II are incorrect.

[10] Which of the following statements are correct? I. Java manages the meaning of the highorder bit by adding an unsigned right shift operator. II. The Java run-time environment is free to use whatever size it wants, as long as the types behave as user declared them. Choice a Only I is correct. Choice b Only II is correct. Choice c .. Both I and II are correct. Choice d Both I and II are incorrect.

[9] Which of the following statements are correct? I. In Java, char is 8-bit type. II. We have negative chars in Java. Choice a Only I is correct. Choice b Only II is correct. Choice c Both I and II are correct. Choice d .. Both I and II are incorrect.

[8] Which of the following statements are correct? I. The simple data types are defined to have an explicit range and mathematical behavior. II. In Java all data types have a strictly defined range. Choice a Only I is correct. Choice b Only II is correct. Choice c .. Both I and II are correct. Choice d Both I and II are incorrect.

[7] Which of the following statements are correct? I. In Java, a byte is a signed 8-bit type entity. II. The smallest integer data type is short. Choice a .. Only I is correct. Choice b Only II is correct. Choice c

Both I and II are correct. Choice d Both I and II are incorrect.

[6] Which of the following statements are correct? I. We can operate on chars as if they are integers. II. Java has a simple data type boolean for logical values. Choice a Only I is correct. Choice b Only II is correct. Choice c .. Both I and II are correct. Choice d Both I and II are incorrect.

[5] Which of the following statements are correct? I. In Java octal values are denoted by a leading zero. II. In Java, the value 09 produces an error. Choice a Only I is correct. Choice b Only II is correct Choice c .. Both I and II are correct. Choice d Both I and II are incorrect.

[4] Which of the following statements are correct? I. The long data type is the most versatile and efficient type. II. Data type determines behavior and not size.

Choice a Only I is correct. Choice b .. Only II is correct. Choice c Both I and II are correct. Choice d Both I and II are incorrect.

[3] Which of the following statements are correct? I. In Java an int is always 32 bits regardless of the particular platform. II. Java supports unsigned, positive-only integers. Choice a Only I is correct. Choice b Only II is correct. Choice c Both I and II are correct. Choice d Both I and II are incorrect.

[2] Which of the following statements are correct? I. In Java, variables of type int are commonly employed to control loops and to index arrays. II. Any time we have an integer expression involving bytes, shorts, ints and literal numbers, the entire expression is promoted to int before the calculation is done. Choice a Only I is correct. Choice b Only II is correct. Choice c Both I and II are correct.

Choice d Both I and II are incorrect.

[1] Which of the following statements are correct? I. Integer literals create an int value. II. In Java, when a literal value is assigned to a byte or short variable, an error is generated even if the literal value is within the range of the target type. Choice a Only I is correct. Choice b Only II is correct. Choice c Both I and II are correct. Choice d Both I and II are incorrect.

Vous aimerez peut-être aussi