What is y after the following switch statement is executed


1. _____ is interpreted.

Pascal
Java
C++
Ada
C

2. What is the printout of the following code?

double x = 5.5;
int y = (int)x;
System.out.println("x is " + x + " and y is " + y);

x is 5.5 and y is 5.0
x is 5.5 and y is 5
x is 5 and y is 6
x is 6 and y is 6
x is 6.0 and y is 6.0

3. What is the value of (double)(5/2)?

2.0
2
3.0
2.5
3

4. Suppose x=10 and y=10, what is x after evaluating the expression (y >= 10) || (x++ > 10)?

9
11
10
Illegal expression

5. What is y after the following switch statement is executed?

x = 3;
switch (x + 3) {
case 6: y = 0;
case 7: y = 1;
default: y += 1;
}

1
4
2
3

6. Analyze the following statement.

double sum = 0;
for (double d = 0; d<10;) {
d += 0.1;
sum += sum + d;
}

The program compiles and runs fine.
The program runs in an infinite loop because d<10 would always be true.
The program has a compile error because the control variable in the for loop cannot be of the double type.
The program has a compile error because the adjustment is missing in the for
loop.

7. What is the value in count after the following loop is executed?

int count = 0;
do {
System.out.println("Welcome to Java");
} while (count++ < 9);
System.out.println(count);

10
9
0
8
11

8. (char)('a' + Math.random() * ('z' - 'a' + 1)) returns a random character _____

between 'b' and 'z'.
between 'a' and 'y'.
between 'a' and 'z'.
between 'b' and 'y'.

9. What is the output of the following code?

public class Test {
public static void main(String[ ] args) {
int[ ] x = {120, 200, 016};
for (int i = 0; i < x.length; i++)
System.out.print(x[i] + " ");
}
}

120 200 16
120 200 20
120 200 14
016 is a compile error. It should be written as 16.

10. Analyze the following code.

public class Test {
public static void main(String[ ] args) {
int[ ] x = new int[5];
int i;
for (i = 0; i < x.length; i++)
x[i] = i;
System.out.println(x[i]);
}
}

The program displays 4.
The program displays 0 1 2 3 4.
The program has a runtime error because the last statement in the main method causes ArrayIndexOutOfBoundsException.
The program has a compile error because i is not defined in the last statement in the main method.

Solution Preview :

Prepared by a verified Expert
C/C++ Programming: What is y after the following switch statement is executed
Reference No:- TGS01475968

Now Priced at $10 (50% Discount)

Recommended (96%)

Rated (4.8/5)