Loops
3 years ago
mteichman
Save
Edit
Host a game
Live GameLive
Homework
Solo Practice
Practice
10 QuestionsShow answers
  • Question 1
    300 seconds
    Q. How many times will the following code print "Welcome to Java"?
    int count = 0;
    while (count < 10) {
     System.out.println("Welcome to Java");
     count++;
    }
    answer choices
    8
    9
    10
    0
  • Question 2
    300 seconds
    Q. What is the output of the following code?
    int x = 0;
    while (x < 4) {
     x = x + 1;
    }
    System.out.println("x is " + x);
    answer choices
    0
    1
    3
    4
  • Question 3
    300 seconds
    Q.  Analyze the following code.
    int count = 0;
    while (count < 100) {
     // Point A
     System.out.println("Welcome to Java!");
     count++;
     // Point B
    }
     // Point C
    answer choices
    count < 100 is always true at Point B 
     count < 100 is always false at Point B
     count < 100 is always true at Point A  and count < 100 is always false at Point C
     count < 100 is always true at Point Coint C
  • Question 4
    300 seconds
    Q. How many times will the following code print "Welcome to Java"?
    int count = 0;
    do {
     System.out.println("Welcome to Java");
     count++;
    } while (count < 10);
    answer choices
    0
    9
    8
    10
  • Question 5
    300 seconds
    Q. Which of the following loops prints "Welcome to Java" 10 times?
    answer choices
    A:
    for (int count = 1; count <= 10; count++) {
     System.out.println("Welcome to Java");
    for (int count = 2; count < 10; count++) {
     System.out.println("Welcome to Java");
    }
    for (int count = 1; count < 10; count++) {
     System.out.println("Welcome to Java");
    }
    for (int count = 0; count <= 10; count++) {
     System.out.println("Welcome to Java");
    }
  • Question 6
    300 seconds
    Q. The following loop displays _______________.
    for (int i = 1; i <= 10; i++) {
     System.out.print(i + " ");
     i++;
    }
    answer choices
    1 2 3 4 5 6 7 8 9
    1 2 3 4 5 6 7 8 9 10
    1 2 3 4 5 
    1 3 5 7 9
  • Question 7
    300 seconds
    Q. What is the output for y?
    int y = 0;
    for (int i = 0; i<10; ++i) {
     y += i;
    }
    System.out.println(y);
    answer choices
    1
    36
    45
    9
  • Question 8
    300 seconds
    Q. How many times is the println statement executed?
    for (int i = 0; i < 10; i++) 
     for (int j = 0; j < 10; j++)
     System.out.println(i * j);
    answer choices
    100
    10
    45
    20
  • Question 9
    30 seconds
    Q. What is the number of iterations in the following loop:
     for (int i = 1; i < n; i++) {
     // iteration
     }
    answer choices
    2*n
     n
    n - 1
    n + 1
  • Question 10
    300 seconds
    Q. What will be displayed when the following code is executed?
     int number = 6;
     while (number > 0) {
     number -= 3;
     System.out.print(number + " ");
     }
    answer choices
    6,3,0
    6,3
    3,0
    0
Report Quiz
Join a game