Java 我如何使用;其中;在数组末尾添加图片的参数?
此方法假定在Java 我如何使用;其中;在数组末尾添加图片的参数?,java,Java,此方法假定在参数值中给出的位置插入图片 我对如何使用where参数感到困惑 这就是我到目前为止所做的: public boolean addPicture( Picture thePicture, int where ) { int index = where; while( index < pictArray.length ) { pictArray[pictArray.length - 1] = thePicture; } re
参数值中给出的位置插入图片
我对如何使用where
参数感到困惑
这就是我到目前为止所做的:
public boolean addPicture( Picture thePicture, int where )
{
int index = where;
while( index < pictArray.length )
{
pictArray[pictArray.length - 1] = thePicture;
}
return true;
}
public boolean addPicture(图片,int-where)
{
int index=其中;
while(索引
如果您已经知道在哪里添加图片,只需将其添加到图片数组索引-1位置上的该位置即可。这是因为java中的索引从0开始。但我们人类从1开始
如根据用户需要将其添加到第三个位置。他在Where变量中输入3。Java必须将其存储在数组的索引2中
PicArray[index-1]=picture;
如果其中是索引,那么赋值语句应该是pictary[index]=图片@Waqas难道你不认为它应该是索引-1:)@Ishankhana好吧,如果where是基于0-index的,那么它就不会了,否则它就不会了-但是在看到代码之后,它看起来好像where是0-basedarray索引是从0开始的