先写点习作熟悉一下JAVA的工作
class monky
{
int[] goods = new int[100];
//getGood作为litte monky的行为成员
void getGood(int good,int i)
{
goods[i] = good;
}
//开始计算扳了多少
void count()
{
int all =0;
for(int i=0;i<100;i++)
{
all = all+goods[i];
System.out.print(goods[i]+",");
}
System.out.println(" ");
System.out.print("总重:"+all);
}
}
class monkyPlay
{
public static void main(String[] args)
{
monky mk = new monky();
for(int i=0;i<100;i++)
//随机产生不同重量的苞谷
mk.getGood((int)(Math.random()*3000),i);
mk.count();
}
}