Course Content
Java Basics
Java Basics
Challenge: Filter Failure Messages
Task
Swipe to begin your solution
Imagine you have a list of system messages, and you need to extract only those containing the word "failure."
Your task is to write a program that creates a new array with only these messages and then prints them to the console.
- Loop through the
logs
array and check each message for the word "failure." - Count how many messages contain the word "failure" and store the result in the
count
variable. - Create a new array,
errorLogs
, with a length equal tocount
. - Loop through the
logs
array again and add only the messages containing "failure" toerrorLogs
. - Print all messages from the
errorLogs
array to the console using afor
loop.
Solution
solution
Switch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?
Thanks for your feedback!
Section 5. Chapter 4
Challenge: Filter Failure Messages
Task
Swipe to begin your solution
Imagine you have a list of system messages, and you need to extract only those containing the word "failure."
Your task is to write a program that creates a new array with only these messages and then prints them to the console.
- Loop through the
logs
array and check each message for the word "failure." - Count how many messages contain the word "failure" and store the result in the
count
variable. - Create a new array,
errorLogs
, with a length equal tocount
. - Loop through the
logs
array again and add only the messages containing "failure" toerrorLogs
. - Print all messages from the
errorLogs
array to the console using afor
loop.
Solution
solution
Switch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?
Thanks for your feedback!
Section 5. Chapter 4
Switch to desktop for real-world practiceContinue from where you are using one of the options below