Java 8 | String Method Practice 3

Student Kim
Buzz Code
Published in
2 min readFeb 15, 2021

Hi guys! Today we’re going to practice the String methods that we’ve seen on the last posts. So before we go it’d be better to check them first.

Question 1. Get the word ‘school’ from the sample String, and store it in the answer String.

String sample = "I'm going to school tomorrow.";
String answer = "";

The answer is on below!

You can use the substring like this. Don’t forget that the substring conclude the words from the first parameter to the one before the second parameter. This time, it shows the words from 13 to 18.

Question 2. Change the word ‘tomorrow’ into ‘today’ in the sample String, and print it out.

String sample = "I'm going to school tomorrow.";

Question 3. Make the program on below.

String[] sample = { "apple", "banana", "grape", "lemon", "grapefruit", "peach", "orange", "melon" };

(1) Use the sample array to make a word searching program.
(2) Users can type the words on the console to search them on the array.
(3) If the words in the array contains the letters what users typed, it prints out those words.
ex) If the user typed -> grape
Console -> grape, grapefruit

I added the variable cnt to count the words that contains the search word, and if there’s nothing, it prints “No result” on the console.

Just like this.

And that’s all for today guys! Thank you for reading my post, see ya!

--

--