We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
This problem is bogus and whoever posted is also bogus. The reason,the method is requiring int, and how to return "Bon Appetite" when the value is 0. Since S.o.u.t is used to print in the main, we need to return the string value. And how to do it. Or another option, if you try to modify inside sout in main, it is also giving error since i have modified. How to fix?
This is my solution:
staticintbonAppetit(intn,intk,intb,int[]ar){// Complete this functioninttotalcost=0;for(inti=0;i<ar.length;i++){totalcost+=ar[i];}totalcost=totalcost-ar[k];if(b-totalcost/2==0){System.out.println("Bon Appetit");}returnb-totalcost/2;}publicstaticvoidmain(String[]args){Scannerin=newScanner(System.in);intn=in.nextInt();intk=in.nextInt();int[]ar=newint[n];for(intar_i=0;ar_i<n;ar_i++){ar[ar_i]=in.nextInt();}intb=in.nextInt();intresult=bonAppetit(n,k,b,ar);System.out.println(result);}
it return "Bon Appetit" and 0 which is incorrect as for problem statement when he does not have to refund.
How to fix it!
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Bill Division
You are viewing a single comment's thread. Return to all comments →
This problem is bogus and whoever posted is also bogus. The reason,the method is requiring int, and how to return "Bon Appetite" when the value is 0. Since S.o.u.t is used to print in the main, we need to return the string value. And how to do it. Or another option, if you try to modify inside sout in main, it is also giving error since i have modified. How to fix?
This is my solution:
it return "Bon Appetit" and 0 which is incorrect as for problem statement when he does not have to refund.
How to fix it!