Ask Question
25 September, 23:51

array of String objects, words, has been properly declared and initialized. Each element of words contains a String consisting of lowercase letters (a-z). Write a code segment that uses an enhanced for loop to print all elements of words that end with "ing". As an example, if words contains {"ten", "fading", "post", "card", "thunder", "hinge", "trailing", "batting"}, then the following output should be produced by the code segment.

+5
Answers (1)
  1. 25 September, 23:54
    0
    for (String s:words)

    if (s. endsWith ("ing"))

    System. out. println (s);

    Explanation:

    Create an enhanced for loop that iterates through the words array

    Check if an element in words ends with "ing" using endsWith () method (Since it is said that strings are lowercase letters, we do not need to check it)

    If you find one that ends with "ing", print the element
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “array of String objects, words, has been properly declared and initialized. Each element of words contains a String consisting of lowercase ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers