Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Filter Failure Messages | String
Java Basics
course content

Course Content

Java Basics

Java Basics

1. Getting Started
2. Basic Types, Operations
3. Loops
4. Arrays
5. String

book
Challenge: Filter Failure Messages

Task
test

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.

  1. Loop through the logs array and check each message for the word "failure."
  2. Count how many messages contain the word "failure" and store the result in the count variable.
  3. Create a new array, errorLogs, with a length equal to count.
  4. Loop through the logs array again and add only the messages containing "failure" to errorLogs.
  5. Print all messages from the errorLogs array to the console using a for loop.

Solution

java

solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 5. Chapter 4
toggle bottom row

book
Challenge: Filter Failure Messages

Task
test

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.

  1. Loop through the logs array and check each message for the word "failure."
  2. Count how many messages contain the word "failure" and store the result in the count variable.
  3. Create a new array, errorLogs, with a length equal to count.
  4. Loop through the logs array again and add only the messages containing "failure" to errorLogs.
  5. Print all messages from the errorLogs array to the console using a for loop.

Solution

java

solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 5. Chapter 4
Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
We're sorry to hear that something went wrong. What happened?
some-alt