WEEK-2
Q1. How many times will the following code print "Welcome to Java"?
int count = 0;
do {
System.out.println("Welcome to Java");
} while (count++ < 10);
A) 11
Q2. Which of the following is the correct expression that evaluates to true if the number x is between 1 and 100 or the number is negative?
A) ((x < 100) && (x > 1)) || (x < 0)
Q3. In Java, the symbol "=" and the symbol "==" are used synonymously (interchangeably).
A) FALS
Q4. What is the output for y?
int y = 0;
for (int i = 0; i < 10; ++i) {
y += i;
}
System.out.println(y);
A) 45
Q5. Assume that x and y are int variables with x = 5, y = 3, and a and d are char variables with a = 'a' and d = 'A', and examine the following conditions:
Condition 1: (x < y && x > 0)
Condition 2: (a != d || x != 5)
Condition 3: !(true && false)
Condition 4: (x > y || a == 'A' || d != 'A')
A) Conditions 2, 3 and 4 are all true, Condition 1 is not
Q6. The following loop is syntactically valid.
for (int j = 0; j < 1000; j++) j--;
A) TRUE
Q7. The statement if (a >= b) a++; else b--; will do the same thing as the statement if (a < b) b--; else a++;.
A) TRUE
Q8. The do loop differs from the while loop in that
A) the do loop will always execute the body of the loop at least once
Q9. An if statement may or may not have an else clause, but an else clause must be part of an if statement.
A) TRUE
Q10. Which of the following statements are true about Java loops?
A) all three loop statements are functionally equivalent
Comments
Post a Comment