1. 程式人生 > >java中求50瓶水,3瓶換一瓶,共換多少瓶

java中求50瓶水,3瓶換一瓶,共換多少瓶

public static void main(String[] args) {
		//50瓶水,3瓶換一瓶,共換多少瓶
		int sum=50;
		int num=sum;
		while (num>=3) {
			sum+=num/3;
			num=num/3+num%3;
			
		}
		System.out.println(sum);
	}