Question
In this problem you'll write code to find all the unique characters in an input String. In order to make the returned data useful, you'll
In this problem you'll write code to find all the unique characters in an input String. In order to make the returned data useful, you'll also return them in alphabetical order. This problem will help you think through how to do both things in the same code.
First of all, you will write a public static method uniqueChars() that takes a String input and returns a String. (Hint: This method does not deal with Scanner or System.out.print(). The String is already given as an input.)
The returned String has the distinct, unique chars of the input String, but they are in alphabetical order (as determined by Java). That means if there are two chars someChar and otherChar in the output, then
- when someChar
- likewise when someChar > otherChar, it comes after otherChar
- it never happens that someChar == otherChar, because we only put unique characters into the output.
Stop now and think for a minute how you might solve this problem. What steps would you break it down into?
... think ...
Stop now and think for a minute how you might do these steps:
1. find the alphabetically lowest character in the input String
2. copy it to the output String
3. find the alphabetically lowest character in the input String that's greater than the previous one
4.copy that one to the output String
5. keep going until you can't find any new characters in the input String.
So, which steps are identical and thus look like they are really the same code inside a loop?
Chapter 7P x | D EE UNDERG E Untitled do x D catalog Ent x e What Do Pr x | M Homework x G Use text art x Answer A28 | G Chegg Stud x | + https://class.mimir.io bassignments/e71e4df7-d820-43ab-9be7-001 145e90f41/do/3a6102ad-d136440-99a8 5e63bb24124e T INFO Homework 7.. Saved Homework 7-more loops including nested 50 polnts possible Reset to Starter Code O Due in 8h 9m UniqueCharsjava New Exit Full Screen 1 public class UniqueChars( 2- public static string uniquechars(string input) [ Question 1 Coding Problem, // The return value String output // Add your code here by filling in the TODO' s 4. Question 2 Coding Problem, 0 TODO 1: Find the lowest char in the input TODO 2: Loop TODO 3: Append the lowest character to output TODO 4: Find a new lowest char that's higher than the old one, and present in input TODO 5: Go back around the loop if there's a new lowest char Question 3 Coding Problem, 10 12 13 14 15 16 17 18 19 Question 4 Coding Problem,15 Question 5 Coding Problem,15 Run Tests return output; Question 6 Coding Problem, Not Run 21 / Invoke the uniqueChars() method with some sample strings 22 public static void main(String[] args) [ 23 24 25 26 Question 7 Coding Problem, System.out.println(uniqueChars ("abracadabra")); Not Run Question 8 Coding Problem, 0 prantint uniqueChars( The uickbroi fox jumps over the lazy dog."): System.out.println(uniquechars ("The quick brown fox jumps over the lazy dog.")): Question 9 Coding Problem,50 Review & Submit 5 questions remaining Chapter 7P x | D EE UNDERG E Untitled do x D catalog Ent x e What Do Pr x | M Homework x G Use text art x Answer A28 | G Chegg Stud x | + https://class.mimir.io bassignments/e71e4df7-d820-43ab-9be7-001 145e90f41/do/3a6102ad-d136440-99a8 5e63bb24124e T INFO Homework 7.. Saved Homework 7-more loops including nested 50 polnts possible Reset to Starter Code O Due in 8h 9m UniqueCharsjava New Exit Full Screen 1 public class UniqueChars( 2- public static string uniquechars(string input) [ Question 1 Coding Problem, // The return value String output // Add your code here by filling in the TODO' s 4. Question 2 Coding Problem, 0 TODO 1: Find the lowest char in the input TODO 2: Loop TODO 3: Append the lowest character to output TODO 4: Find a new lowest char that's higher than the old one, and present in input TODO 5: Go back around the loop if there's a new lowest char Question 3 Coding Problem, 10 12 13 14 15 16 17 18 19 Question 4 Coding Problem,15 Question 5 Coding Problem,15 Run Tests return output; Question 6 Coding Problem, Not Run 21 / Invoke the uniqueChars() method with some sample strings 22 public static void main(String[] args) [ 23 24 25 26 Question 7 Coding Problem, System.out.println(uniqueChars ("abracadabra")); Not Run Question 8 Coding Problem, 0 prantint uniqueChars( The uickbroi fox jumps over the lazy dog."): System.out.println(uniquechars ("The quick brown fox jumps over the lazy dog.")): Question 9 Coding Problem,50 Review & Submit 5 questions remainingStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started