小编Anu*_*aPL的帖子

Java错误:非法启动表达式

我基本上正在完善,完成并尝试从java初学者的参考书中编译测试代码.目标是创建一个猜谜游戏,其中目标位于3个连续的单元格中(我将位置保持在一个数组中),用户猜测单元格为否.通过细胞破坏靶细胞.

我在同一个错误中检查了六个帖子,但我无法弄清楚出了什么问题.

这是我的错误:

test.java:5: error: illegal start of expression
 public int[] locations={1,2,3};
 ^
1 error
Run Code Online (Sandbox Code Playgroud)

我的代码是:

public class test{

        public static void main(String[] args){

            test dot=new test();
            public int[] locations={1,2,3};

            dot.setLocationCells(locations);

            String userGuess="2";
            String result = dot.checkYourself(userGuess);
            String testResult="failed";

            if(result.equals("hit")){
                testResult="passed";
            }


          System.out.println(testResult);
        }

public String checkYourself(String stringGuess){
        int guess=Integer.parseInt(stringGuess);
        String result="miss";
        int numOfHits=0;

        for(int cell:locations){
            if(guess==cell){
                result="hit";
                numOfHits++;
                break;
                }
            }

        if(numOfHits==locations.length){
            result="kill";
            }

       System.out.println(result);
       return result;
    }


public void setLocationCells( int[] locations){
        int[] locns;
        locns=locations;
        }

}
Run Code Online (Sandbox Code Playgroud)

java compiler-errors

14
推荐指数
2
解决办法
22万
查看次数

管道和过滤器之间的差异?

我是shell脚本的新手,我想知道管道和过滤器之间的区别.他们似乎都做同样的事情.甚至格式也是一样的.

ls -l | grep user |cat >user
Run Code Online (Sandbox Code Playgroud)

管道还是过滤器?

bash shell

3
推荐指数
1
解决办法
1391
查看次数

标签 统计

bash ×1

compiler-errors ×1

java ×1

shell ×1