Multiply value in array

0

How do I multiply the elements of an array? What am I doing wrong?

For example, if I have:

int numbers[]={1,2,2,4,5,6};

and my card_block is 2, the remainder would give 1x4x5x6 = 120;

int countCards(int [] cards, int BLOCK_CARD){
  int quant=0;
  int count =0;
  for (int i=0; i<cards.length; i++){
   if(cards[i]!=BLOCK_CARD)
  count=cards[i];
  count=count*cards[i];

   quant=count;
  }
  return quant;
}
    
asked by anonymous 19.03.2018 / 00:51

1 answer

0

Try this:

  int countCards(int [] cards, int BLOCK_CARD){
  int quant=0;
  int count =1;
  for (int i=0; i<cards.length; i++){
   if(cards[i]!=BLOCK_CARD){

  count=count*cards[i];
}
   quant=count;
  }
  return quant;
}
    
19.03.2018 / 01:13