From the course: Spring Boot 2.0 Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Solution: Build a CommandLineRunner

Solution: Build a CommandLineRunner

From the course: Spring Boot 2.0 Essential Training

Start my 1-month free trial

Solution: Build a CommandLineRunner

(upbeat music) - [Instructor] Now it's time for my solution to this challenge. In order to solve this challenge I created a new module called fizz-buzz. And what's in that module, I actually implemented one method. In the application I created a beam of type command line runner, and just like we did before, when we walked through it together, I simply returned the ads. Now within there, I created a four loop. So I did four, one less than one on one and increment every time. I set the result of my string equal to blank. Then I added to it if there was modular three and that equals zero, I did fizz. If it was modular five, I added buzz. This way, if it's divisible by three, but not five, I get fizz. If it's divisible by five and not three, I get buzz. And if it's divisible by both, I get fizz-buzz. Now, if it's neither of those, you'll see on line 22 then that if the result is not empty, print the result…

Contents