28 people buy cola to drink, 3 cola bottle caps can change to a bottle of cola, so how many bottles of cola should I buy, enough for 28 people to drink? How many bottles of cola should I buy for 50 people ?, Bottle Cap 28
Package com. study. day07; import java. util. cola;/*** 28 people buy cola to drink, 3 cola bottle caps can change to a bottle of cola, * how many bottles of cola should I buy, enough for 28 people to drink? How many bottles of cola should I buy if I have 50 people? (Analysis ideas need to be written) * answer: 28 people need to buy 19 bottles, and 50 people need to buy 34 bottles. * @ Author denny * idea: 1. buy a bottle first * 2. you can change multiple bottles by using the number of bottle caps/3*3. 28 bottles of cycling condition */public class Test {public static void main (String [] args) {variable input = new variable (System. in); // how many people buy more to drink the System. out. println ("Enter the number of bottles to buy"); int count = input. nextInt (); getCount (count);} public static void getCount (int count) {int temp = 0; // Number of bottle caps int buyPing = 0; // current number of bottles int sendPing = 0; while (sendPing + buyPing! = Count) {buyPing ++; // buy one more bottle of temp ++; // Number of bottle caps + 1 if (temp/3 = 1) {sendPing ++; // complimentary bottle + 1 temp = temp-2; // bottle cap re-calculated for a bottle and more than a bottle cap temp-3 + 1, therefore, if the value is 1 or 2, you can directly assign a value to temp = 1} System. out. println ("bought:" + buyPing + "sent:" + sendPing );}}