Topic: [菜鸟cargo的问题]20060315(Re: length)

  Print this page

1.[菜鸟cargo的问题]20060315(Re: length) Copy to clipboard
Posted by: cargo
Posted on: 2006-03-15 14:41



我是新手,看着CORE JAVA 学习入门,遇到一个问题,请大家别笑它简单,对我来说还是问题呢....

谢谢!

2.Re:[菜鸟cargo的问题]20060315 [Re: cargo] Copy to clipboard
Posted by: Skybus
Posted on: 2006-03-15 15:04

It's not recommended to post you code like this . Post your code using text mode!

For your question.both balance and balance[i] are array variables;They have no difference in syntax,but they differ in semantce. balance.lenght means the lenght of the wole array,but balance[i].lenght means the lenght of the array banlance[i].They can't be exchanged each other!

3.Re:[菜鸟cargo的问题]20060315(Re: length) [Re: cargo] Copy to clipboard
Posted by: why
Posted on: 2006-03-15 17:30

Skybus:
Thanks but please try to spell check before you post.

For your question, both balance and balance[i] are array variables.
They have no difference in syntax, but they differ in semantics.
balance.length means the length of the "whole array" (array of arrays), but balance[i].length means the length of the array balance[i]. They can't be exchanged with each other!

BTW, we seldom say "it's recommendatory to do something", but rather "it's recommended to do something", or "something is recommendatory to somone".


cargo:
Indeed it's not recommended to post your source code listing as an image. If it is really necessary, you could use a lower JPEG quality factor (say, 70%) to reduce the size of the image.
Thanks.

4.Re:[菜鸟cargo的问题]20060315(Re: length) [Re: cargo] Copy to clipboard
Posted by: leior
Posted on: 2006-03-15 18:15

balance.length:NYEARS
balance[i].length:NRATES

5.Re:[菜鸟cargo的问题]20060315(Re: length) [Re: cargo] Copy to clipboard
Posted by: surroad
Posted on: 2006-03-15 18:40

二维数组不同维的长度

6.Re:[菜鸟cargo的问题]20060315(Re: length) [Re: cargo] Copy to clipboard
Posted by: Skybus
Posted on: 2006-03-15 18:52

to why:
Thanks a lot for your attention,It's my careless mistake,I'll try to avoid it in the fulture !

7.Re:[菜鸟cargo的问题]20060315(Re: length) [Re: cargo] Copy to clipboard
Posted by: cargo
Posted on: 2006-03-16 01:08

谢谢大家了,
可是对二维数组自动填充的时候:
for (int i=1;i<balance.length;i++)
{
   for (int j=0;j<balance[i].length;j++)
   {
     double oldBalance=balance[i-1][j];
     double interest=oldBalance*interestRate[j];
     balance[i][j]=oldBalance+interest;
   }
}

二维数组可以理解成“小数组的数组”,如果中间那个“for”循环是给每“行”小数组按列赋值的话,那么外面的“for”循环就是确定了小数组的行数。
那么第一个for中的“i<balance.length”似乎不太合理,它的意义是整个二维数组中的所有小数组的个数,而不是行数,对吗?

8.Re:[菜鸟cargo的问题]20060315(Re: length) [Re: cargo] Copy to clipboard
Posted by: jackyangf
Posted on: 2006-03-17 14:54

首先 balance 是一个数组 那么 balance.length 是一个整型,表示这个数组的长度
特别一点的是,这个balance数组里的元素 也是数组,那么他们也有各自的长度
可以肯定的一点是: 这个大数组的长度(包含的小数组的个数)肯定不需要和小数组的长度一致

这些是对 balance 数组的说明
另外一点是对数组 这种类型来说, 它的长度 .length 是一个只读的变量;不能修改的。所以你没有办法用任何东西来替换它,除非你不要这个数组了,另外在创建一个长度不同的。

9.Re:[菜鸟cargo的问题]20060315(Re: length) [Re: cargo] Copy to clipboard
Posted by: jackyangf
Posted on: 2006-03-17 14:57

balance[0] lenth = 5 O O O O O \
balance[1] lenth = 5 O O O O O - balance length = 3
balance[2] lenth = 5 O O O O O /

10.Re:[菜鸟cargo的问题]20060315(Re: length) [Re: cargo] Copy to clipboard
Posted by: cargo
Posted on: 2006-03-20 16:23

谢谢jackyangf的回答,我了解了:对于这个balance树组,balance.lentgh的数量不是大树组中所有数字的数量,而是其中的树组的数量,也就是大树组中的元素的“行数”!

再次谢谢jackyangf和上面所有的大虾~~~~


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923