问题:矿泉水1块钱1瓶,喝完以后,2个空瓶子可以换一瓶新矿泉水。问:花10块钱最后最多能得多少瓶矿泉水。
解答:
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int result = 0;
if(n<=0){
System.out.println(0);
}else{
while(n!=0){
result+=n;
n = n/2;
}
}
System.out.println(result+1);
}
}