S
S
shurupin2021-12-08 17:31:44
Java
shurupin, 2021-12-08 17:31:44

What's wrong with Java "foreach"?

I wanted to pass a test task for qualification, the task is simple, check the brackets.
I made it in IDEA, it works,

public static boolean isValid(String braces) {
                ArrayDeque stack = new ArrayDeque ();
                for(char ch: braces.toCharArray()){
                    switch (ch) {
                        case '(': stack.add(0); break;
                        case '[':stack.add(1); break;
                        case '{': stack.add(2); break;
                        case ')':{if(stack.isEmpty() || (Integer) stack.pollLast()!=0) return false; else  break;}
                        case ']':{if(stack.isEmpty() ||  (Integer) stack.pollLast()!=1) return false; else  break;}
                        case '}':{if(stack.isEmpty() ||   (Integer) stack.pollLast()!=2) return false; else  break;}
                        default: break;
                    }
                }
                return stack.isEmpty() ? true: false;
            }

threw for the answer Turing issued:
Compiling...
Main.java:12: error: cannot find symbol
for(char ch: braces.toCharArray()){
^
symbol: variable braces
location: class Solution
Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error

Test Result: Failed

more precisely: 61b0bc8ea2a32959788320.jpeg

Since then, I have been tormented by the question a lot, what could be wrong?

I checked the code on many platforms, it works everywhere. For example, www.codewars.com:
61b0bd498c0fd017686652.jpeg

https://onecompiler.com/ :
61b0c14441e4a636167210.jpeg
I asked a question in Turing's chat, they told me that they would consider it and get in
touch, they got in touch, but in the answer only that I can continue to be tested (as I understand the template), no communication options.

I gradually came to the conclusion that Turing is buggy, which, of course, creates an unpleasant impression about the service and the quality of tests, and, apparently, work in the future.

But again, I return to the idea that maybe I just don’t know something, and in vain I’m so on a well-known service ...
Therefore, if someone can shed light on this mystery, I will be grateful))

PS The answer is found, yes, the service is normal, it's my fault: I'm
61b0c92e054d7395471667.jpeg
used to IntelliJ IDEA. you can’t miss something like that there
and you can’t change the method signature in Turing, but trust in the service has returned, and with it the prospects))

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Orkhan, 2021-12-08
Hasanly @azerphoenix

But again, I come back to the idea that maybe I just don’t know something, and in vain so on a well-known service ...
Therefore, if someone can shed light on this mystery,

I can assume the following, the site you specified uses java 7, and foreach appeared in version 8. Accordingly, either it should be possible to select the java version, or use a for loop

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question