@Test public void whenBracketCheckThreeLinesThenResultTrueFalseFalse() { BracketCheck bracket = new BracketCheck(); assertThat(bracket.checkLine("()(()((())))"), is(true)); assertThat(bracket.checkLine("())"), is(false)); assertThat(bracket.checkLine("())(()"), is(false)); }
public boolean checkLine(String line) { String[] arrayOfBrackets = line.split(""); int flag = 0; boolean result = true; for (String element : arrayOfBrackets) { if (element.equals("(")) { flag++; } else if (element.equals(")")) { flag--; } if (flag < 0) { result = false; } } return result; }
BracketCheck { public boolean checkLine(String line) { String[] arrayOfBrackets = line.split(""); int flag = 0; boolean result = true; for (String element : arrayOfBrackets) { if (element.equals("(")) { flag++; } else if (element.equals(")")) { flag--; } if (flag < 0) { result = false; } } return result; } }
BracketCheck { public boolean checkLine(String line) { String[] arrayOfBrackets = line.split(""); int flag = 0; boolean result = true; for (String element : arrayOfBrackets) { if (element.equals("(")) { flag++; } else if (element.equals(")")) { flag--; } if (flag < 0) { result = false; } } return result; }  }
BracketCheck { public boolean checkLine(String line) { String[] arrayOfBrackets = line.split(""); int flag = 0; boolean result = true; for (String element : arrayOfBrackets) { if (element.equals("(")) { flag++; } else if (element.equals(")")) { flag--; } if (flag < 0) { result = false; } } return result; }  boolean checkLine(String line); }
BracketCheck { public boolean checkLine(String line) { String[] arrayOfBrackets = line.split(""); int flag = 0; boolean result = true; for (String element : arrayOfBrackets) { if (element.equals("(")) { flag++; } else if (element.equals(")")) { flag--; } if (flag < 0) { result = false; } } return result; }  boolean checkLine(String line);  }