我已经给这个数组在类中用于赋值。如何用数组调用此方法?有可能吗?
/**
* compactHand - THIS METHOD IS SUPPLIED FOR YOU!
* re-order the array so that all cards occupy the early indices, i.e. 0,1,2,...
* and that all the nulls are in the higher indices.
* Also count the number of cards in the array and set ncard accordingly.
* Example: if array is [Kclub][null][2diamond][null][7spade]
* then this routine sets array to [Kclub][2diamond][7spade][null][null] and sets ncard to 3.
* Note that the relative order of cards is not changed.
*/
private void compactHand(){
int nc=0, ix=0, nullix=-1;
// find first null
do{
if (cards[ix]==null){
nullix = ix;
break;
}
} while (++ix<cards.length);
if (nullix==-1){
// there were no nulls. set ncards and return.
ncard = cards.length;
return;
}
nc = nullix;
// loop to end of array and swap cards for nulls
for(ix=nullix; ix<cards.length; ix++)
if (!(cards[ix]==null)){
cards[nullix++] = cards[ix];
cards[ix] = null;
nc++;
}
ncard = nc;
}
我已经完成了大部分的任务,但对于的方法之一,我需要在一个阵列命名为卡内它调用此方法。我试着用调用它:
cards.compactHand();
该方法不接受数组作为参数,但我需要完成的方法,说明具体说明来使用它。
/**
* delete Cards at specified indices and compact the array.
* if any indices do not correspond to cards then the array must be unchanged
* and this member returns false.
* otherwise the specified cards are deleted, the array compacted and true returned.
* @param index index of array element to delete
* @return true if all elements successfully deleted, false if none deleted.
*/
该方法被标记为私有,但我可以访问它,因为它在同一个类中。
任何帮助,这将不胜感激。
问题是什么? – dat3450
_我已经给了这个数组在一个类中用于赋值._请给我们看这个类。 –