运行会出错,拜托有时间的给看看!!!
创建一个含有10个元素的Alone6_2的数组ob,使其满足下列条件,并使其像下面提示进行输出:
条件:
ob[0].a=1,ob[0].b=2
ob[i+1].a=ob[i].a+ob[i].b;
ob[i+1].b=ob[i].a*ob[i].b;
结果: 
ob[0].a=1,ob[0].b=2
ob[1].a=3,ob[1].b=2
ob[2].a=5,ob[2].b=6
...... 
代码:
public class Alone6_2
{
  private int a,b;
  public Alone6_2(){}
  public void setAB(int a,int b)
  {
    this.a=a;
    this.b=b;
  }
  public int getA()
  {
   return a;
  }
  public int getB()
  {
   return b;
  }
  public static void main(String[] args)
  {
   Alone6_2[] ob=new Alone6_2[10];
   for(int i=0;i<ob.length;i++)
   {
    ob[i]=new Alone6_2();
    ob[0].setAB(1,2);
   for(int i=1;i<ob.length;i++)
   {
    ob[i+1].a=ob[i].a+ob[i].b;
    ob[i+1].getA();
    ob[i+1].b=ob[i].a*ob[i].b;
    ob[i+1].getB();
    System.out.println("ob["+i+"]"+".a"+"="+ob[i].a);
    System.out.println("ob["+i+"]"+".b"+"="+ob[i].b);
   }
   
  
  }
}

解决方案 »

  1.   

    楼主的代码有三个大的错误,我改过来了,楼主仔细看看吧.
    public class Alone6_2 {
    private int a, b; public Alone6_2() {
    } public void setAB(int a, int b) {
    this.a = a;
    this.b = b;
    } public int getA() {
    return a;
    } public int getB() {
    return b;
    } public static void main(String[] args) {
    Alone6_2[] ob = new Alone6_2[10];
    ob[0] = new Alone6_2();
    ob[0].setAB(1, 2);
    System.out.println("ob[" + 0 + "]" + ".a" + "=" + ob[0].a);
    for (int j = 0; j < ob.length - 1; j++) {
    ob[j + 1] = new Alone6_2();
    ob[j + 1].a = ob[j].a + ob[j].b;
    ob[j + 1].getA();
    ob[j + 1].b = ob[j].a * ob[j].b;
    ob[j + 1].getB();
    System.out.println("ob[" + (j + 1) + "]" + ".a" + "=" + ob[j + 1].a);
    System.out.println("ob[" + (j + 1) + "]" + ".b" + "=" + ob[j + 1].b);
    }
    }
    }
    //console
    ob[0].a=1
    ob[1].a=3
    ob[1].b=2
    ob[2].a=5
    ob[2].b=6
    ob[3].a=11
    ob[3].b=30
    ob[4].a=41
    ob[4].b=330
    ob[5].a=371
    ob[5].b=13530
    ob[6].a=13901
    ob[6].b=5019630
    ob[7].a=5033531
    ob[7].b=1058399894
    ob[8].a=1063433425
    ob[8].b=-1642014574//Int的最大值是:2147483647,此处乘法已经超出该最大值,窄转换使数据失真.
    ob[9].a=-578581149
    ob[9].b=117143346
      

  2.   

    推荐使用eclipse IDE,我想楼主还是在用记事本吧,有些错误是不应该的.