Skip to content

Instantly share code, notes, and snippets.

@tonkatsu7
Created July 10, 2018 05:27
Show Gist options
  • Save tonkatsu7/97d8dab299138247b440549a78d5cec8 to your computer and use it in GitHub Desktop.
Save tonkatsu7/97d8dab299138247b440549a78d5cec8 to your computer and use it in GitHub Desktop.
CoderByte challenge Simple Symbols
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