10-2 "乞丐"

时间:2021-04-08 12:54:22   收藏:0   阅读:0
比较for和while
技术图片
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public class HelloWorld {
    public static void main(String[] args) {
           
        //使用while打印0到4    
        int i = 0;
        while(i<5){
            System.out.println("while循环输出的"+i);
            i++;
        }
          
        //使用for打印0到4    
        for (int j = 0; j < 5; j++) {
            System.out.println("for  循环输出的"+j);
        }
    }
}
 示例 2 : 

练习-乞丐 

天朝有一个乞丐姓洪,去天桥要钱
第一天要了1块钱
第二天要了2块钱
第三天要了4块钱
第四天要了8块钱
以此类推

问题: 洪乞丐干10天,收入是多少?
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!