0

the variable s is not increasing already tried several forms, pass by parameter, global variable, nothing is right

public static int p(int m,int p,int t,int s ){
   int resultado;      
   if(m == 0 ){
      s++;
      resultado =  s;          
   } 
   else if(m == 1){
      s++;
      resultado =  t;
   }      
   else {
      s++;
      resultado =  2*p(m-1,p,t,s) + p(m-2,p,t,s);
   }      
   return s ;      
}
kritikaTalwar
  • 1,730
  • 1
  • 17
  • 25
  • You probably wan to return `resultado`, not `s`. – Eran Apr 30 '18 at 05:21
  • `s` is passed by value, so when you do `s++` in your method, you do not increment the variable you've passed. Try replacing it with an `AtomicInteger`. But better rewrite your code so that you won't need to rely on side effects (like changes to the arguments you've passed). – lexicore Apr 30 '18 at 05:37
  • I'm a beginner, can you give me an example? I just need to count the number of terms each call – Gabriel de Oliveira Sousa May 01 '18 at 01:42

0 Answers0