课程: Java Algorithms
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Solution: Reverse each word
- [Instructor] Let's create an algorithm that reverses each word in a sentence. The first step is to check if the input falls into a base case category. This is where the sentence is null or the sentence is empty. If that's the case, we'll return the empty string. Now we're ready to implement the core of the function. Let's create a result variable to hold our end result. This'll be a StringBuilder because we'll slowly build up our result with each reversed word before we return it from the function. For this challenge, we're reversing each individual word, not the entire input string itself. In order to reverse, we'll need to pluck out each word so we can individually reverse it. We can use the split function on the input to create an array of words. Each word is separated by spaces. The split function separates the input string into separate strings, splitting on the space, which is the delimiter character we've added…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。
内容
-
-
-
Validate Strings in Java: All-or-nothing properties4 分钟 17 秒
-
(已锁定)
Validate strings in Java: Specific properties2 分钟 58 秒
-
(已锁定)
Normalize strings in Java4 分钟 38 秒
-
(已锁定)
Basic parsing and searching strings in Java3 分钟 39 秒
-
(已锁定)
Apply custom parsing to search algorithms3 分钟 24 秒
-
(已锁定)
Create algorithm-driven strings in Java3 分钟 46 秒
-
(已锁定)
Leverage built-in tools to generate custom data2 分钟 30 秒
-
(已锁定)
Solution: Reverse each word3 分钟 32 秒
-
-
-
-
-
-
-