//不知道为什么,编译不能通过
public class Temp
{
int arr[]=new int[30];
arr[1]=100;
public static void main(String args[])
{
System.out.println(arr[1]);
}
}

解决方案 »

  1.   

    public class Temp
    {
    static int arr[]=new int[30]; public static void main(String args[])
    {
                       arr[1]=100;
    System.out.println(arr[1]);
    }
    }
      

  2.   

    或者:public class Temp
    { public static void main(String args[])
    {
    int arr[]=new int[30];
    arr[1]=100;
    System.out.println(arr[1]);
    }
    }
      

  3.   

    你有两个错误,第一个arr[1]=100;应该出现在一个方法中,因为它是一条单独的赋值语句,跟int i=0;是不一样的,int i=0;是给变量一个初始化的值,而你的是作为一句单独的语句是不行的。
    就像
    public class Temp
    {
    int i=0;
    arr[1]=100;
    public static void main(String args[])
    {
    }
    }可以,但是
    public class Temp
    {
    int i;
    i=0;
    arr[1]=100;
    public static void main(String args[])
    {
    }
    }
    却不可以,因为i=0;出现在了声明的部分。第二个错误
    System.out.println(arr[1]);
    因为你的arr声明是个非static的,所以它是不能在static方法中被引用的。
      

  4.   

    在java的类体中,只有变量的定义与方法的定义。
      

  5.   

    我相信随便找个ide都可以提示LZ的错误的,lz本身对类的概念没有理解好
      

  6.   

    除了初始化赋值外,其他的赋值语句必须包含在方法里面
    [http://www.willwell.cn]
      

  7.   

    除了初始化赋值外,其他的赋值语句必须包含在方法里面
    <font color="#FF000"><a herf="http://www.willwell.cn">http://www.willwell.cn</a></font>
      

  8.   

    因为你的arr声明是个非static的,所以它是不能在static方法中被引用的。