Ask Question
26 September, 10:00

How many times does the following loop execute? int upperCaseLetters = 0; String str = "abcdEfghI"; boolean found = false; for (int i = 0; i < str. length () &&! found; i++) {char ch = str. charAt (i); if (Character. isUpperCase (ch)) {found = true; }}

+3
Answers (1)
  1. 26 September, 11:40
    0
    Five times

    Explanation:

    Given the codes as follows:

    int upperCaseLetters = 0; String str = "abcdEfghI"; boolean found = false; for (int i = 0; i < str. length () &&! found; i++) { char ch = str. charAt (i); if (Character. isUpperCase (ch)) { found = true; } }

    The for loop will stop when the first uppercase letter is found in the str. This condition is set in the for loop condition (i < str. length () &&! found)

    Since the the first upper case letter is the fifth character in the given str, the for loop will run for five rounds. In the fifth round the condition in the if statement (Line 9) will be evaluated to true and then set the true value to found variable (Line 11). This will terminate the loop in the next iteration.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “How many times does the following loop execute? int upperCaseLetters = 0; String str = "abcdEfghI"; boolean found = false; for (int i = 0; ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers