码迷,mamicode.com
首页 > 其他好文 > 详细

解题.for; block scope; while; "2 to the " + i + " power is " + result

时间:2014-12-11 22:19:51      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:style   blog   ar   color   sp   for   java   div   log   

 1 package com.java7;
 2 
 3 public class WhileDemo {
 4     public static void main(String[] args) {
 5         int e;
 6         int result;
 7         for(int i = 0; i < 10; i++){
 8             result = 1;
 9             e = i;
10             while(e > 0){
11                 result *= 2;
12                 e--;
13             }
14             
15         System.out.println("2 to the " + i + " power is " + result);
16         }
17     }
18 }

 执行过程:

1: i = 0; result = 1; e = 0;

2: i = 1; result = 1; e = 1; result = result(1)*2 = 2; e = 0; end loop;

3: i = 2; result = 1; e = 2; result = result(1)*2 = 2; e = 1; result = result(2)*2 = 4; e = 0; end loop;

4: // ...

解题.for; block scope; while; "2 to the " + i + " power is " + result

标签:style   blog   ar   color   sp   for   java   div   log   

原文地址:http://www.cnblogs.com/fatoland/p/4158586.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!