Java: Check whether a specified character is happy or not
Write a Java program to check whether a specified character is happy or not. A character is happy when the same character appears to its left or right in a string.
Visual Presentation:
Sample Solution:
Java Code:
Sample Output:
The given string is: azzlea Is z happy in the string: true The given string is: azmzlea Is z happy in the string: falses
Flowchart:
For more Practice: Solve these Related Problems:
- Write a Java program to determine if every occurrence of a specified character in a string has at least one identical neighbor.
- Write a Java program to check if a given character in a string is surrounded by the same character on either side.
- Write a Java program to verify the "happiness" of a target character by scanning its adjacent positions in the string.
- Write a Java program to return true if all instances of a specified letter in a string have matching adjacent characters.
Java Code Editor:
Improve this sample solution and post your code through Disqus
Previous: Write a Java program to count the number of triples (characters appearing three times in a row) in a given string.
Next: Write a Java program to return a string where every appearance of the lowercase word 'is' has been replaced with 'is not'.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.