Created
July 10, 2018 05:27
-
-
Save tonkatsu7/97d8dab299138247b440549a78d5cec8 to your computer and use it in GitHub Desktop.
CoderByte challenge Simple Symbols
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import java.io.*; | |
import java.util.regex.Matcher; | |
import java.util.regex.Pattern; | |
class Main { | |
public static String SimpleSymbols(String str) { | |
Pattern regex = Pattern.compile("[a-zA-Z]"); | |
Matcher match = regex.matcher(str); | |
while (match.find()) | |
if (match.start() == 0 || match.end() == str.length()) // check not bookends | |
return "false"; | |
else if (str.charAt(match.start() - 1) != '+' || str.charAt(match.start() + 1) != '+') // check + either side | |
return "false"; | |
return "true"; | |
} | |
public static void main (String[] args) { | |
// keep this function call here | |
Scanner s = new Scanner(System.in); | |
System.out.print(SimpleSymbols(s.nextLine())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment