求高手解答!!!!!

卷发的玉米 2009-02-22 01:36:12
类rui定义如下:
public class rui{
private int a,b;
public rui(){}
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) {}
}
创建含有10个元素的rui数组ob使其满足以下条件 并向下面这样输出:
条件:
ob[0].a=1;
ob[0].b=2;
ob[i+1].a=ob[i].a+ob[i].b;
ob[i+1].a=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
ob[3].a=11,ob[3].b=30



求高手解答一下这题
...全文
92 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
tjbklx33 2009-02-22
  • 打赏
  • 举报
回复
..
leongdz 2009-02-22
  • 打赏
  • 举报
回复
学习中
ZiSheng 2009-02-22
  • 打赏
  • 举报
回复

public class Test{
private long a,b;
public Test(){}
public void setAB(long a,long b){
this.a=a;
this.b=b;
}
public long getA(){
return a;
}
public long getB(){
return b;
}
public static void main(String[] args) {
Test [] t1=new Test[5];
for(int i=0;i<t1.length;i++){
t1[i]=new Test();
}
t1[0].setAB(1, 2);
for(int i=1;i<t1.length;i++){
t1[i].setAB((t1[i-1].getA())+(t1[i-1].getB()), t1[i-1].getA()*t1[i-1].getB());
}
for(int i=0;i<t1.length;i++){
System.out.println("t1["+i+"]:a:"+t1[i].getA()+" b:"+t1[i].getB());
}
}
}
a3070 2009-02-22
  • 打赏
  • 举报
回复
没看懂
爱摸鱼de老邪 2009-02-22
  • 打赏
  • 举报
回复
你敲错了吧:
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=1+2=3;ob[1].b=1*2=2;
ob[2].a=3+2=5;ob[2].b=3*2=6;
ob[3].a=5+6=11;ob[3].b=5*6=30

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧