class test
{
int[] str;
str=new int[2];
str[0]=25;
str[1]=50;
public static void main(String[] args)
{

}}
=====================
出错:
test.java:4: 需要 <标识符>
        str=new int[2];
           ^
test.java:5: 需要 ']'
        str[0]=25;
            ^
test.java:5: 需要 <标识符>
        str[0]=25;
                 ^
test.java:6: 需要 ']'
        str[1]=50;
            ^
test.java:6: 需要 <标识符>
        str[1]=50;
                 ^
5 错误=========
也不知道为什么我都没有分给?CSDN没给我分啊。

解决方案 »

  1.   

    int[] str;
    {
      str=new int[2];
      str[0]=25;
      str[1]=50;
    }
      

  2.   

    str=new int[2];
    str[0]=25;
    str[1]=50;
    三句要写在方法里面要是写在main里面要加staticps:每天登录就有分了
      

  3.   

    java新手...不能这样写的,下面的代码作了两件事:声明变量 和 初始化
    int[] str;
    str=new int[2];
    str[0]=25;
    str[1]=50;
    关键是 你把声明和初始化的操作分开了,造成的结果是初始化的代码
    str=new int[2];
    str[0]=25;
    str[1]=50;
    没有作用域
    你可以声明成静态的 
    static int[] str;
    static {
    str=new int[2];
    str[0]=25;
    str[1]=50;}
    或者放在构造函数里int[] str;
    public test() {
    str=new int[2];
    str[0]=25;
    str[1]=50;}
      

  4.   

    zdjray(PubSoft) 你的说法有错误,
    str=new int[2];
    str[0]=25;
    str[1]=50;
    上面3句只是执行初始化,不一定要放在方法里的
      

  5.   

    int[] str;
    public test() {
    str=new int[2];
    str[0]=25;
    str[1]=50;}
      

  6.   

    呵呵,分号代表是语句,是要执行的,语句的执行是必须放到方法里的,可以这样说,除了变量的声明及初始化,所有的你要JAVA执行的东西,都是必须写的方法(函数)里的。
      

  7.   

    多写代码,就有经验了,str[0]=25;
    str[1]=50; 要放在方法里
      

  8.   

    要这么声明可以这么写
        public class Test {
     int[] str=new int[]{25,50};
     public static void main(String[] args){

    }
         }
    如果要在main方法里使用需将str定义成static