From the course: Learning Java 11
Unlock the full course today
Join today to access over 24,000 courses taught by industry experts.
Solution: Move capital letters - Java Tutorial
From the course: Learning Java 11
Solution: Move capital letters
- [Instructor] Let's implement this function. To keep track of our new string, we'll use a string builder. We'll also create an int to keep track of where we should insert the next capital letter. We want to move the capital letters to the beginning of the list so it'll start off at 0. Then we'll iterate through the input string. We'll retrieve each character using the charAt method. Now we need to decide at what index should we put this character in our result. This will depend on whether the character is a capital letter. We can use the isUpperCase method from the character class to check if a given character is uppercase. Now, if the character is not uppercase, we can append it to the back of the string builder. Its ordering should remain the same. If the character is uppercase, we'll want to insert it at the beginning of the list. Now, if there's more than one capital letter in the list, this won't work. Each…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
(Locked)
What are functions? (conceptually)4m 25s
-
(Locked)
Defining functions in Java3m 28s
-
(Locked)
Calling functions in Java5m 9s
-
(Locked)
Parameters in Java5m 30s
-
(Locked)
Return types in Java5m 34s
-
(Locked)
Using built-in functions in Java4m 43s
-
(Locked)
Solution: Move capital letters2m 27s
-
(Locked)
-
-