fork(1) download
  1. class Ideone {
  2. public static boolean check(String text) {
  3. // char[] convertText = text.toCharArray();
  4. int counter = 0;
  5.  
  6. for ( int i = 0, last = text.length(); i < last; i++ ) {
  7. if ( text[i] == '(' ) {
  8. counter += 1;
  9. } else if ( text[i] == ')' ) {
  10. counter -= 1;
  11. }
  12. if ( counter < 0 ) {
  13. return false;
  14. }
  15. }
  16. if ( counter > 0 ) {
  17. return false;
  18. }
  19. return true;
  20. }
  21.  
  22. public static void main (String[] args) {
  23. String text = "ol(o)lo";
  24.  
  25. System.out.println(check(text) ? "True" : "False");
  26. }
  27. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:7: error: array required, but String found
			if ( text[i] == '(' ) {
			         ^
Main.java:9: error: array required, but String found
			} else if ( text[i] == ')' ) {
			                ^
2 errors
stdout
Standard output is empty