Java: Check whether the character immediately before and after a specified character is same in a given string
80. Check Char Surrounded by Same Char
Write a Java program to check whether the character immediately before and after a specified character is the same in a given string.
Visual Presentation:
Sample Solution:
Java Code:
Sample Output:
The given string is: moon#night The before and after character are same: true The given string is: bat##ball The before and after character are same: false The given string is: #moon#night The before and after character are same: true
Flowchart:
For more Practice: Solve these Related Problems:
- Write a Java program to check if the characters adjacent to a specified character in a string are identical.
- Write a Java program to verify if for every occurrence of a given character, the preceding and succeeding characters match.
- Write a Java program to determine if a character in a string is flanked by the same character on both sides.
- Write a Java program to scan a string and return true if the character immediately before and after a given target are equal.
Go to:
PREV : Remove Middle Char in 'z?g' Pattern.
NEXT : Compare 3-char and 4-char Substrings.
Java Code Editor:
Improve this sample solution and post your code through Disqus
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.