Java multiple choice question 1Consider the following statem
Java multiple choice question
___1.Consider the following statements.
double x;
String y;
y = String.format(\"%.2f\", x);
If x = 43.579, what is the value of y?
A.\"43\" B.\"43.57\" C. \"43.58\" D. none of these
___2. Which of the following is correct syntax for a Java comment block?
A.# Enter Comments Here
B. Enter Comments Here
C. /*Enter Comments Here*/
D. **Enter Comments Here**
___3. Suppose that x, y and z are int variables. The expression x(y+z) in Java is written as ____.
A. x * y + z B. x * (y + z) C. y + x * z D. None of these
____4. Suppose that x is an int variable. Which of the following expression always evaluates to true?
A. (x > 0) || ( x <= 0) B. (x > 0) || (x == 0) C. (x > 0) && ( x <= 0) D.(x > 0) && (x == 0)
____5. What is the value of counter after the following statements executes?
int counter = 0;
while (counter <= 50) {
counter = counter + 1;
}
A. 48 B.50 C.51 D.53
____6. What is the output of the following Java code?
int j;
for (j = 10; j <= 10; j++)
System.out.print(j + \" \");
System.out.println(j);
A.10 B. 10 10 C. 10 11 D. 11 11
____7. Which of the following loops is guaranteed to execute at least once?
A. counter-controlled while loop
B. for loop
C. do...while loop
D. sentinel-controlled while loop
____8. Which of the following is the loop condition in the following for loop?
for (i = 1; i < 20; i++)
System.out.println(\"Hello World\");
System.out.println(\"!\");
A.i = 1; B. i<20; C. i++ D. System.out.println(\"Hello World\");
____9. Given
int one; double two; boolean four;
which of the following assignment statements are valid?
(i) xx = 7 + 3 % 4;
(ii) 2.3 + 3.5 = two;
(iii) four = (2 <= 3);
A. Only (i) is valid
B. (i) and (ii) are valid
C. (ii) and (iii) are valid
D. only (iii) is valid
____10. What is the output of the following program segment?
int x = 14;
int y = 60;
while (((y - x) % 3) != 0) {
System.out.print(y + \" \");
y = y - 5;
}
System.out.println();
A. 60 55 B. 60 55 50 C. 60 55 50 45 D. None of these
Solution
43.58
/*Enter Comments Here*/
B. x * (y + z)
(x > 0) || ( x <= 0)
51
C. 10 11
C. do...while loop
B. i<20;
D. only (iii) is valid
A. 60 55


