How do I make this method print the actual coins used to make thechange. Please
ID: 3609621 • Letter: H
Question
How do I make this method print the actual coins used to make thechange.Please help. I need to somehow modify this method to print theactual coins.
public static int changeByRecur(int[] coins,int change)
{
int minCoins=change;
for(inti=0;i<coins.length;i++){
if(coins[i]==change){
return 1;
}
}
for(intj=1;j<=change/2;j++){
intthisCoins=changeByRecur(coins,j)
+changeByRecur(coins,change-j);
if(thisCoins<minCoins)
{
minCoins=thisCoins;
}
}
return minCoins;
}
Explanation / Answer
please rate - thanks there has to be a better way, but I think this will work in main program declare your new arrays and counters System.out.println(changeByRecur(coins,change,denom,count,tempdenom,tempcount)); print denom[0] through denom[count-1] public static intchangeByRecur(int[] coins,int change,int denom[],intcount,tempdenom[],int tempcount) //public static int changeByRecur(int[] coins,int change) { int minCoins=change; for(inti=0;iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.