选择题
编程题
题目1
import java.util.Scanner;public class Main {public static int res(int n) {int sum = 0;//n = 10while (n > 1) {sum += n / 3;n = n / 3 + n % 3;//借空汽水瓶if (n == 2) {sum += 1;return sum;}}return sum;}public static void main(String[] args) {Scanner sc = new Scanner(System.in);//三个空汽水瓶可以换一瓶汽水//允许向老板借空汽水瓶(但是必须要归还)//本题存在多组输入。输入的 0 表示输入结束,并不用输出结果。int n = 0;while ((n = sc.nextInt()) != 0) {System.out.println(res(n));}sc.close();}
}