Skip to content

Instantly share code, notes, and snippets.

@kishida
Created January 23, 2016 19:37
Show Gist options
  • Save kishida/4011703d73b2608d2f43 to your computer and use it in GitHub Desktop.
Save kishida/4011703d73b2608d2f43 to your computer and use it in GitHub Desktop.
Single thread program.
public class SingleThread {
public static void main(String[] args) {
StringBuilder sb = new StringBuilder();
String str = "abc(cdef)gh(ijk)lmn";
int i = 0;
boolean inParenthesis = false;
for(;;){
if(i >= str.length()){
break;
}
char ch = str.charAt(i);
switch(ch){
case '(':
inParenthesis = true;
break;
case ')':
inParenthesis = false;
break;
default:
if(inParenthesis){
sb.append(ch);
}
}
++i;
}
System.out.println(sb);
}
}
@kishida
Copy link
Author

kishida commented Jan 23, 2016

Output only in a parenthesis.

cdefijk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment