买房子--新浪微薄话题#Google笔试试题#

 

 

/**
 *
 */
package base;

/**
 * http://t.sina.com.cn/k/Google%25E7%25AC%2594%25E8%25AF%2595%25E8%25AF%2595%25E9%25A2%2598
 * 据说是#Google笔试试题#  现在北京有一套房子,价格200万,假设房价每年上涨10%,一个软件工程师每年固定能赚40万。
 * 如果他想买这套房子,不贷款,不涨工资,没有其他收入,每年不吃不喝不消费,那么他需要几年才能攒够钱买这套房子?
 * A. 5年 B. 7年 C. 8年 D. 9年 E. 永远买不起
 *
 * @author yangwm Sep 28, 2010 04:22:43 PM
 */
public class BuyHouse {

    /**
     * @param args
     */
    public static void main(String[] args) {
        int i = 0;
        long housePrice = 2000000;
        long salary = 0;
        while (salary < housePrice && i < 100) {
            housePrice += housePrice * 0.1;
            salary += 600000;
            i++;
            System.out.println(i + " years later, salary " + salary + ", housePrice " + housePrice);
        }
        System.out.println("oh, my god! " + i + " years later, salary "
                + salary + ", house price " + housePrice + ", I can not buy a house!");
    }

}

 

 

年赚40万输出:

1 years later, salary 400000, house price 2200000
2 years later, salary 800000, house price 2420000
3 years later, salary 1200000, house price 2662000
4 years later, salary 1600000, house price 2928200
5 years later, salary 2000000, house price 3221020
6 years later, salary 2400000, house price 3543122
7 years later, salary 2800000, house price 3897434
8 years later, salary 3200000, house price 4287177
9 years later, salary 3600000, house price 4715894
10 years later, salary 4000000, house price 5187483
......
99 years later, salary 39600000, house price 25055628576
100 years later, salary 40000000, house price 27561191433
oh, my god! 100 years later, salary 40000000, house price 27561191433, I can not buy a house!

 

修改为年赚60万输出:(社会还是很阳光的)

1 years later, salary 600000, house price 2200000
2 years later, salary 1200000, house price 2420000
3 years later, salary 1800000, house price 2662000
4 years later, salary 2400000, house price 2928200
5 years later, salary 3000000, house price 3221020
6 years later, salary 3600000, house price 3543122
oh, my god! 6 years later, salary 3600000, house price 3543122, I can not buy a house!

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值