如何从while循环返回2个布尔值?Java的

Cha*_*oir 1 java boolean return while-loop

我尝试返回correctPiece和correctDest但是

return correctPiece;
Run Code Online (Sandbox Code Playgroud)

加下划线并出现错误"无法访问的代码".

我怎么能两个都回来?

   while(correctPiece && !correctDest) {

            System.out.println("Click on a destination");

            toXCo = s.getToXInt();
            toYCo = s.getToYInt();

            Move found = null;

            for( Move m : moves){
                //checks if move can be done
                if (m.ToX() == toXCo && m.ToY() == toYCo){
                    //if move is allowed- exit loop
                    found = m; 
                    correctDest = true;
                }
            }

            if (found == null) {
                //if move can't be, ask for new co-ordinates
                System.out.println("This move is not legal \n");
                    correctDest = false;
                    correctPiece = false;
            }   
            return correctDest;
            return correctPiece;
        }
Run Code Online (Sandbox Code Playgroud)

Ell*_*sch 5

通过将您的return类型更改为boolean[]和使用类似的东西

return new boolean[] { correctDest, correctPiece };
Run Code Online (Sandbox Code Playgroud)