28人买可乐喝,3个可乐瓶盖可以换一瓶可乐,那么要买多少瓶可乐,够28人喝?假如是50人,又需要买多少瓶可乐?
package com;
import java.util.Scanner;
public class Test10 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入人数");
int nextInt = sc.nextInt();
if(nextInt>0){
System.out.println(cola(nextInt));
}else{
System.out.println("请重新输入");
}
}
public static int cola(int num){
int colacnt=0;
int cnt=0;
while(cnt<num){
colacnt++;
cnt++;
if(cnt%3==0)
cnt++;
}
return colacnt;
}
}