Consider the following block of Java code. How many times will it output "Hello"?

1
2
3
4
for (int i = 1; i < 10; i--)
{
    System.out.println("Hello");
}

Select one:

  • a. 0
  • b. 9
  • c. 1
  • d. 10
  • e. Way too many!

Notice the update, "i--". "i" starts less than 10 and just keeps getting smaller. (The loop is technically not infinite. "i" will eventually reach the most-nega tive value that "int" can represent, and then it wil l wrap around to the largest possible "int", ending the loop.) The correct answers are: 1, Way too many!

Related Posts

0 Comments

12345

    00