0

How do I print out a letter and space only from a string in Java?

29th Oct 2020, 9:07 PM
Victor Ukoha
Victor Ukoha - avatar
4 Answers
+ 4
Can you be more specific? Give an example of input and expected output etc.
29th Oct 2020, 9:42 PM
ChaoticDawg
ChaoticDawg - avatar
+ 3
Ah, ok... There are a few ways to solve this challenge. I think one of the easiest to explain without giving you the code is this. Start by getting the input String and converting it to a char array "str.toCharArray()". Make a new empty String variable to hold the output string String output = "". Now all you need to do is loop over the elements of the char array and check if each element is either a letter "Character.isLetter(ch)" or a space "Character.isWhitespace(ch)". If true then add that element to the front of the output String variable (output = ch + output), effectively reversing the string in the process. Then after the loop, print the output variable.
30th Oct 2020, 7:12 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
Thanks a million
31st Oct 2020, 8:26 AM
Victor Ukoha
Victor Ukoha - avatar
0
Exactly spy Life challenge..
30th Oct 2020, 1:41 PM
Victor Ukoha
Victor Ukoha - avatar