变量在我的Java应用程序中不起作用

时间:2013-07-23 22:43:57

标签: java

我尝试编译这个字符串:

public class Dimensions
{
    public static void main( String[] args )
    {
        boolean[][] points = new boolean[5][20] ;
        points[0][5] = true ;
        points[1][6] = true ;
        points[2][7] = true ;
        points[3][8] = true ;
        points[4][9] = true ;
        for ( int i = 0 ; i < points.length ; i++ )
        {
            System.out.println( "\n" ) ;
        }
        for ( int j = 0 ; j < points.length ; j++)
        {
            char mark = ( points[i][j] ) ? 'X' : '-' ;
            System.out.println( mark ) ;
        }
    }
}

但是javac给了我错误

  

Dimensions.java:17:错误:找不到符号                           char mark =(points [i] [j])? 'X' : '-' ;                                                ^符号:变量i location:class Dimensions 1 error

它就像i甚至不存在。提前致谢

1 个答案:

答案 0 :(得分:4)

一旦i循环结束,您的变量for就会超出范围。

也许你的意思是将j for循环嵌套在i for循环中。然后i仍然在整个j for循环的范围内。