日期:2014-05-20  浏览次数:20707 次

关于 clear() 数组的问题
import java.util.*;
public class Slide{
    private char[][] cells;

    public Slide(){
        cells= new char[][]{
            {'@','@','@','@'},
            {'@','@','@','@'},
            {'@','@','@','@'},
            {'@','@','@','@'}
        }; 

    }

    public Slide(char[][] cells){
        for(int row=0; row<cells.length; row++)
            for(int column = 0; column<cells[row].length; column++)

                this.cells = cells;
    }

    public void print(){
        {
            for(char[] a: cells){

                for(char c: a){// 3这里提示错误 不能往下走 怎么改。请大家给点建议
                    System.out.print(c+" ");
                }

                System.out.println();            
            }

        }


    }

    public void clear(){ /1/当运行这个的时候 
        Arrays.fill(cells,null);//2所有的数组取消 回到 print()

    }

    public void project(Slide other){
    }

    public void move(int row, int col){
    }
}
数组

------解决方案--------------------
可以把 clear 改成:

            for(char[] a: cells){
                Arrays.fill(a,null);          
            }