static int num=0;

//char layOut[4][4] = {'p','.','.','p','.','#','.','#','P','#','.','.','#','p','#','p'};
static char[][] layOut = new char[4][4]{'p','.','.','p','.','#','.','#','P','#','.','.','#','p','#','p'};

SeekFriend()
{
//layOut[4][4] = {"p",".",".","a","#","#","b",".","c",".",".","#","#","#","d","."};
// xLocation = 0;
// yLocation = 0;
// length = 0;
}。       public MyStack ms = new MyStack();错误提示:
--------------------Configuration: <Default>--------------------
D:\Java\TopCoderEx\SeekFriend.java:13: ';' expected
    static char[][] layOut = new char[4][4]{'p','.','.','p','.','#','.','#','P','#','.','.','#','p','#','p'};
                                               ^
D:\Java\TopCoderEx\SeekFriend.java:61: illegal start of expression
        public MyStack ms = new MyStack();
                ^
2 errors

解决方案 »

  1.   

    语法问题,
    第一个改成char[][] layout = {{'p','.','.','p'},{'.','#','.','#'},{'P','#','.','.'},{'#','p','#','p'}};
    第二个你应该是在方法内部定义的ms吧,方法内部不能用public,去掉就ok
      

  2.   

    第一个问题: 改成如下的格式。当用初始化块的方式定义数组时不用给定数组数量,而是直接定义。 static char[][] layOut = new char[][]{{'p','.','.','p'}, {'.','#','.','#'}, {'P','#','.','.'} ,{'#','p','#','p'}};
    第二个问题看不出来,给的代码不够。也有可能是和第一个问题想关的。有时候前面的问题解决,后面的问题也就不是问题了。你先试试吧。
      

  3.   

    第二个为啥你会想到加public?
      

  4.   

    Up java 超级群 :有时间大家共同交流 51177847
      

  5.   

    因为本来没加~
    出现20个问题!!就是这个类中的所有方法都提示找不到!
    但是这个类就在这个文件的下面紧接着编写的~!
    加上以后就直接提示 illegal start of expression
      

  6.   

    thank u!
    第一个问题是解决了~
    第二个~本来也没加那个public ~可是去掉它就会提示ms中的方法都找不到~(ms定义在main方法中)
    MyStack是紧接着下面写得~
    class MyStack //FILO
    {
    private LinkedList ll = new LinkedList();
    public void push(Object o)
    {
    ll.addFirst(o);
    }
    public Object pop()
    {
    return ll.removeFirst();
    }
    public Object peek()
    {
    return ll.getFirst();
    }
    public boolean empty()
    {
    return ll.isEmpty(); //判断是否为空列表
    }
    }
      

  7.   

    第二个问题
    main函数中的变量是不能用public,protected,private访问权限修饰词的。
    class MyStack 和main函数在不在一个文件里?
    如果在,去掉public以后是可以看到ms中的方法的。
      

  8.   

    第一个问题
    static char[][] layOut = new char[][]{{'p','.','.','p'}, {'.','#','.','#'}, {'P','#','.','.'} ,{'#','p','#','p'}};
    第二个问题
    如果MyStack ms是类属性 你可以放到定义类属性的地方
    如果是方法内部属性 那需要把public去掉
      

  9.   

    方法内部本来就不能定义public,为什么呢?我也不知道!要看规范!
    可以参考下http://www.99inf.net/SoftwareDev/Java/29764.htm
      

  10.   

    import java.util.*;class SeekFriend
    { static int xLocation = 0;
    static int yLocation = 0;
    static int length = 0;
    static int num=0;

    //char layOut[4][4] = {'p','.','.','p','.','#','.','#','P','#','.','.','#','p','#','p'};
    static char[][] layOut = new char[][]{{'p','.','.','p'},{'.','#','.','#'},{'P','#','.','.'},{'#','p','#','p'}};

    SeekFriend()
    {
    //layOut[4][4] = {"p",".",".","a","#","#","b",".","c",".",".","#","#","#","d","."};
    // xLocation = 0;
    // yLocation = 0;
    // length = 0;
    } static boolean left(char[][] layOut,int x,int y)
    {
    if(x-1<0)return false;
    return layOut[x-1][y]!='#';
    }

    static boolean right(char[][] layOut,int x,int y)
    {
    if(x+1>3)return false;
    return layOut[x+1][y]!='#';
    }

    static boolean down(char[][] layOut,int x,int y)
    {
    if(y+1>3)return false;
    return layOut[x][y+1]!='#';
    }
    static void getFriend()
    {
    System.out.println("Get "+num+" friend,"
    +"it's name is "+layOut[xLocation][yLocation]);
    }


    static boolean doSeek(char[][] layOut)
    {
    length++;
    switch(layOut[xLocation][yLocation])
    {
    // case '#':break;
    case '.':break;
    default:num++;getFriend();break;
    }
    }     

    public static void main(String[] args)
    {
    // MyStack ms = new MyStack();
    MyStack ms = new MyStack();

    for(;xLocation<4;xLocation++)
    {
    ms.push(Integer.valueOf(length));
    ms.push(Integer.valueOf(xLocation));
    ms.push(Integer.valueOf(yLocation));
    doSeek(layOut);

    for(;down(layOut,xLocation,yLocation);)
    {
    yLocation++;
    if(rigth(layOut,xLocation,yLocation))
    {
    ms.push(length);
    ms.push(xLocation);
    ms.push(yLocation);
    while(rigth(layOut,xLocation,yLocation))
    {
    xLocation++;
    doSeek(layOut);
    }

    yLocation = ms.pop().intValue();
    xLocation = ms.pop().intValue();
    length    = ms.pop().intValue();
    }
    if(left(layOut,xLocation,yLocation))
    {
    ms.push(Integer.valueOf(length));
    ms.push(Integer.valueOf(xLocation));
    ms.push(Integer.valueOf(yLocation));
    while(left(layOut,xLocation,yLocation))
    {
    xLocation--;
    doSeek(layOut);
    }
    yLocation = ms.pop().intValue();
    xLocation = ms.pop().intValue();
    length    = ms.pop().intValue();
    }
    yLocation = ms.pop().intValue();
    xLocation = ms.pop().intValue();
    length    = ms.pop().intValue();
    }
    }
    }
    }
    class MyStack //FILO
    {
    private LinkedList ll = new LinkedList();
    public void push(Object o)
    {
    ll.addFirst(o);
    }
    public Object pop()
    {
    return ll.removeFirst();
    }
    public Object peek()
    {
    return ll.getFirst();
    }
    public boolean empty()
    {
    return ll.isEmpty(); //判断是否为空列表
    }
    }
    第一个问题在各位的帮助下解决了~
    可是还没有解决第二个问题~
    这是所有程序~拜托了~
      

  11.   

    错误改完了,运行还是有问题,你自己看看;
    import java.util.*; class SeekFriend
    {    static int xLocation = 0;
        static int yLocation = 0;
        static int length = 0;
        static int num=0;
        
        //char layOut[4][4] = {'p','.','.','p','.','#','.','#','P','#','.','.','#','p','#','p'};
        static char[][] layOut = new char[][]{{'p','.','.','p'},{'.','#','.','#'},{'P','#','.','.'},{'#','p','#','p'}};
        
        SeekFriend()
        {
            //layOut[4][4] = {"p",".",".","a","#","#","b",".","c",".",".","#","#","#","d","."};
    //        xLocation = 0;
        //    yLocation = 0;
        //    length = 0;
        }    static boolean left(char[][] layOut,int x,int y)
        {
            if(x-1<0)return false;
            return layOut[x-1][y]!='#';
        }
        
        static  boolean right(char[][] layOut,int x,int y)
        {
            if(x+1>3)return false;
            return layOut[x+1][y]!='#';
        }
        
        static boolean down(char[][] layOut,int x,int y)
        {
            if(y+1>3)return false;
            return layOut[x][y+1]!='#';
        }
        static void getFriend()
        {
            System.out.println("Get "+num+" friend,"
                                +"it's name is "+layOut[xLocation][yLocation]);
        }
        
        
        static boolean doSeek(char[][] layOut)
        {
            length++;
            switch(layOut[xLocation][yLocation])
            {
    //            case '#':break;
                case '.':break;
                default:num++;getFriend();break;            
            }
            return true;
        }                                
        
        public static void main(String[] args)
        {
        //    MyStack    ms = new MyStack();
            MyStack ms = new MyStack();
            
            for(;xLocation<4;xLocation++)
            {
                ms.push(Integer.valueOf(length));
                ms.push(Integer.valueOf(xLocation));
                ms.push(Integer.valueOf(yLocation));
                doSeek(layOut);    
                        
                for(;down(layOut,xLocation,yLocation);)
                {
                    yLocation++;
                    if(right(layOut,xLocation,yLocation))  错误 rigth-> right 跟上面写的方法名不一致
                    {    
                        ms.push(length);
                        ms.push(xLocation);
                        ms.push(yLocation);    
                        while(right(layOut,xLocation,yLocation))  错误 rigth ->right
                        {
                                xLocation++;
                                doSeek(layOut);                        
                        }
                        
                        yLocation = ((Integer) ms.pop()).intValue(); 
                        xLocation = ((Integer) ms.pop()).intValue();
                        length    = ((Integer) ms.pop()).intValue();    
                    }
                    if(left(layOut,xLocation,yLocation))
                    {
                        ms.push(Integer.valueOf(length));
                        ms.push(Integer.valueOf(xLocation));
                        ms.push(Integer.valueOf(yLocation));
                        while(left(layOut,xLocation,yLocation))
                        {
                                xLocation--;
                                doSeek(layOut);                        
                        }                            
                        yLocation = ((Integer) ms.pop()).intValue();
                        xLocation = ((Integer) ms.pop()).intValue();
                        length    = ((Integer) ms.pop()).intValue();                        
                    }
                yLocation = ((Integer) ms.pop()).intValue();
                xLocation = ((Integer) ms.pop()).intValue();
                length    = ((Integer) ms.pop()).intValue();    
                }
            }
        }
    }
    class MyStack                    //FILO
    {
            private LinkedList ll = new LinkedList();
            public void    push(Object o)
            {
                    ll.addFirst(o);
            }
            public Object    pop()
            {
                    return ll.removeFirst();
            }
            public Object peek()
            {
                    return    ll.getFirst();    
            }
            public boolean empty()
            {
                    return ll.isEmpty();    //判断是否为空列表
            }
    }